Django redirect() problem help !!! | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

Django redirect() problem help !!!

My Django project has only one app wiki, projects index goes to appā€™s index page which is 127.0.0.1:8000 I am at the url: 127.0.0.1:8000/wiki/newpage This urlā€™s view: . . return redirect(fā€wiki/{title}ā€) My all URLs list is as follows for the wiki app: 1. ā€œā€ 2. wiki/newpage 3. wiki/random 4. wiki/<str:search> <ā€” url I want to redirect 5. wiki/ <ā€” url is for query search But the view returns: wiki/wiki/{title} I tried removing the wiki from redirect() and it becomes fā€/{title}ā€ but now this goes to 127.0.01:8000/{title} I finally want the answer to redirect to 127.0.0.1:8000/wiki/{title} Thank you in advance.

12th Sep 2020, 8:24 AM
Adarsh Mamgain
Adarsh Mamgain - avatar
1 Resposta
+ 2
You should write return redirect(f"/wiki/{title}") to achieve this (with slash at the beginning). Also you can think about using reverse() function instead of hardcoding path for redirect.
12th Sep 2020, 9:09 AM
gambler