Django重定向功能保留旧的网址路径 [英] Django redirect function keep old url path
问题描述
问题是,当我尝试在视图函数中使用 django.shortcuts.redirect
时,Django并不只是从 return redirect('url',)
,但将希望的网址路径添加到当前网址.
示例
当前网址为:/home/page1
在按钮上按下页面时,我调用视图功能:返回重定向('**/home/page2 **',)
此后,我反而希望网址/home/page2 我收到/home/page1/home/page2
如何摆脱陈旧网址部分来自重定向?
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?
推荐答案
在注释中,您具有:
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')
这篇关于Django重定向功能保留旧的网址路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!