【问题标题】:django-user-accounts don't redirect after successful logindjango-user-accounts 登录成功后不重定向
【发布时间】:2018-11-05 13:08:34
【问题描述】:

我在我的项目中使用django-user-accounts 应用程序。我无法理解奇怪的行为。当用户尝试登录时,没有任何反应。成功登录后,我想重定向用户。为什么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")),

模板/帐户/login.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

【问题讨论】:

标签: python django pinax


【解决方案1】:

登录重定向设置必须是简单明了的字符串。对这些使用 reverse 是行不通的。

文档是here

ACCOUNT_LOGIN_REDIRECT_URL = '/dashboard/'

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

【讨论】: