L
L
Leonid2019-11-06 17:54:33
Django
Leonid, 2019-11-06 17:54:33

How to compose a redirect regular expression in Django?

When moving from the old site, many pages remained with such addresses
https://mysite.ru/14-prodaja-vsego/?pag=10000&page...
https://mysite.ru/14-prodaja-vsego?pag=50&page= 9++...
https://mysite.ru/14-prodaja-pvsego/?pag=50&page=8
https://mysite.ru/14-prodaja-vsego/?pag=30&page=6+...
they give a 404 error
, I want to insert a regular expression in urls.py to redirect, ideally to
https://mysite.ru/14-prodaja-vsego/?pag=10000&page... to https://mysite.ru/14-prodaja -vsego/?page=9
https://mysite.ru/14-prodaja-pvsego/?pag=50&page=8 to https://mysite.ru/14-prodaja-pvsego/?page=8
and so on, but it is possible and simple:
https://mysite.ru/14-prodaja-pvsego/
Django has a RedirectView, but how do you make a regular expression?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sparkit, 2019-11-14
@sparkit

You can use re_path instead of path when resolving url.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question