Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django redirect function keep old url path

Tags:

python

django

The problem is when I try to use django.shortcuts.redirect in my view function, Django doesn't simply opening new url path from return redirect('url',) but add wished url path to current url.
Example
Current url is: /home/page1
On page on button press I call views function which: return redirect ('**/home/page2**',)
After this, instead wished url /home/page2 I recieve /home/page1/home/page2

How to get rid of old url part from redirection?

EDIT:
Solved by deleting cookies and search history from browser (Chrome), and code work perfectly fine!

like image 323
FirePower Avatar asked Oct 19 '25 13:10

FirePower


1 Answers

In the comments you have:

return redirect ('home/page2',)

This is incorrect. The url must start with a slash, otherwise it will be treated as a relative url. Change it to:

return redirect ('/home/page2')
like image 93
Alasdair Avatar answered Oct 22 '25 05:10

Alasdair



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!