Python Django-使用重定向\u到\u登录
我想在我的视图中使用Python Django-使用重定向\u到\u登录,python,django,url,login,Python,Django,Url,Login,我想在我的视图中使用重定向到\u登录。由于某些原因,我被重定向到登录两次(因此URL格式不正确) 我的TestView(View)看起来像这样(相关部分): MyURL.py(相关部分): 当我在浏览器中键入localhost:8000/test/时,我的结果是 http://localhost:8000/login/?next=/%3Fnext%3D/test/ 而非预期 http://localhost:8000/login/?next=/test/ 你知道问题出在哪里吗?如果您需要更多文件
重定向到\u登录
。由于某些原因,我被重定向到登录两次(因此URL格式不正确)
我的TestView(View)
看起来像这样(相关部分):
MyURL.py
(相关部分):
当我在浏览器中键入localhost:8000/test/
时,我的结果是
http://localhost:8000/login/?next=/%3Fnext%3D/test/
而非预期
http://localhost:8000/login/?next=/test/
你知道问题出在哪里吗?如果您需要更多文件,请询问。此
/%3Fnext%3D/test/
等于/?next=/test/
您只需通过单词测试即可。在回报中,应该是这样的:
return redirect_to_login('/test/')
有关重定向到\u登录的详细信息
请尝试使用self.request.get\u raw\u uri()
而不是完整路径
url(r'^test/$', TestView.as_view()),
return redirect_to_login('/test/')