我转到我的网页http://localhost:8000/listings/post/
,但未通过测试
@user_passes_test(lambda u: u.is_authenticated() and u.get_profile().shipper)
正如所料,并将我重定向到http://localhost:8000/login/?next=/listings/post/
,就像它应该的那样,但是当我再次登录时,它并没有像我想象的那样将我重定向回那个页面。我需要/accounts/profile/
。我没有在任何地方定义redirect_field_name
,所以它应该寻找默认的next
变量。相关的urls.py
位看起来像这样
url(r'^login/$', 'django.contrib.auth.views.login', name='login'),
那么可能的原因是什么?
答案 0 :(得分:15)
需要添加
<input type="hidden" name="next" value="{{ next }}" />
到我的登录表单。它回发到登录URL ,没有 next
令牌,然后尝试重定向。
答案 1 :(得分:4)
它会将您重定向到设置变量LOGIN_REDIRECT_URL
。
如果满足以下条件,则会发生这种情况:
if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
redirect_to = settings.LOGIN_REDIRECT_URL
很可能你的'next'变量是空的或包含垃圾。