问题描述
我添加django.contrib.auth.views.login 到处都是我的网页,因为我必须加载的(即返回AuthenticationForm)在我base.html文件。这templatetags包括注册/ login.html的
模板。
I added django.contrib.auth.views.login everywhere in my webpage, for that I had to load a templatetag (that returns the AuthenticationForm) in my base.html. This templatetags includes the registration/login.html
template.
登录工作确定,但我想它的用户重定向到同一页面他们登录之前。现在,它重定向我/ wherever_i_am /登录至极显示注册/ login.html的
与Login好或登录失败的消息,但没有base.html文件的剩余部分
The login is working ok but I want it to redirect the users to the same page they are before login. Now, it redirects me to /wherever_i_am/login wich shows registration/login.html
with the 'login ok' or 'login fails' messages but without the rest of base.html.
我按照Django文档而像几个SO问题,但我不能正确重定向。我已经修改了接下来
变量,但它似乎没有工作(下一= {{} request.get_full_path}
重定向我/ wherever_i_am /登录...再次)
I have followed django documentation and a few SO questions like this but I cannot redirect correctly. I have modified the next
variable but it doesn't seem to work (next={{ request.get_full_path }}
redirects me to /wherever_i_am/login ...again)
您是否尝试过类似的东西?任何想法?
Have you tried something similar? any ideas?
UPDATE1
现在的问题可能是这样的:我必须声明我自己的登录视图,如果我要到处包含登录表单在我的网页的
感谢您。
推荐答案
找到答案:
在您的settings.py更改settings.LOGIN_REDIRECT_URL,
Change settings.LOGIN_REDIRECT_URL in your settings.py,
低于code是复制从Django的:
below code is copy from django:
if request.method == "POST":
form = authentication_form(data=request.POST)
if form.is_valid():
# Ensure the user-originating redirection url is safe.
if not is_safe_url(url=redirect_to, host=request.get_host()):
redirect_to = settings.LOGIN_REDIRECT_URL
...
这篇关于Django的 - 登录后如何重定向django.contrib.auth.views.login?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!