成功登录后,django-user-accounts不会重定向

时间:2018-05-26 08:44:59

标签: python django pinax

我在我的项目中使用django-user-accounts app。我无法理解奇怪的行为。当用户尝试登录时没有任何反应。成功登录后,我想重定向用户。为什么ACCOUNT_LOGIN_REDIRECT_URL设置不起作用?

settings.py:

ACCOUNT_LOGIN_REDIRECT_URL = reverse_lazy('dashboard')

我也尝试使用LOGIN_REDIRECT_URL = reverse_lazy('dashboard'),但结果是一样的。

urls.py:

url(r"^account/", include("account.urls")),

模板/帐户/ l​​ogin.html的:

<form method="post" action="">
    {% csrf_token %}
    {% render_field form.username|add_class:"form-control" placeholder="Username" %}
    {% render_field form.password|add_class:"form-control" placeholder="Password" %}
    <input type="hidden" name="next" value="{{ next }}"/>
</form>

控制台中,我会看到下一步:

[26/May/2018 14:31:38] "GET /account/login/ HTTP/1.1" 200 4018

1 个答案:

答案 0 :(得分:2)

登录重定向设置需要是简单的&amp;简单的字串。使用reverse进行这些操作无效。

文档为here

ACCOUNT_LOGIN_REDIRECT_URL = '/dashboard/'

如果您需要执行任何复杂的重定向操作,例如找出用户已登录的内容&amp;重定向到某个地方,然后在上面设置一个视图,其中包含逻辑,以执行您需要执行的操作。

相关问题