使用django-allauth登录后如何为用户设置登陆页面

How to set the landing page for user after login with django-allauth

我的项目 urls.py 中有以下内容:

path('accounts/', include('allauth.urls')),
path('survey/',include(('survey.urls','survey'), namespace='survey')),

在我的项目中 setting.py:

LOGIN_REDIRECT_URL='survey/'

当我进入我的应用程序的登录页面并单击提交时。而不是得到 http://localhost:8000/survey/ 并被重定向到我的应用程序的主页,我得到: http://localhost:8000/accounts/login/survey/ 给出了这个错误:

Using the URLconf defined in TestAllAuth.urls, Django tried these URL patterns, in this order:

    admin/
    accounts/ signup/ [name='account_signup']
    accounts/ login/ [name='account_login']
    accounts/ logout/ [name='account_logout']
    accounts/ password/change/ [name='account_change_password']
    accounts/ password/set/ [name='account_set_password']
    accounts/ inactive/ [name='account_inactive']
    accounts/ email/ [name='account_email']
    accounts/ confirm-email/ [name='account_email_verification_sent']
    accounts/ ^confirm-email/(?P<key>[-:\w]+)/$ [name='account_confirm_email']
    accounts/ password/reset/ [name='account_reset_password']
    accounts/ password/reset/done/ [name='account_reset_password_done']
    accounts/ ^password/reset/key/(?P<uidb36>[0-9A-Za-z]+)-(?P<key>.+)/$ [name='account_reset_password_from_key']
    accounts/ password/reset/key/done/ [name='account_reset_password_from_key_done']
    accounts/ social/
    survey/
    ontoSecConRule/


The current path, accounts/login/usecase/, didn't match any of these.

如您所见,错误消息中有 usecase/ 路径,但我没有到达。

用户通过身份验证后,我在哪里设置页面(url)?

我想我想出了问题所在。

我用 LOGIN_REDIRECT_URL='/survey/'

替换了 LOGIN_REDIRECT_URL='survey/'
from django.core.urlresolvers import reverse_lazy

LOGIN_REDIRECT_URL = reverse_lazy('survey:the_name_of_url')

重定向可以用这个方法,既然给定了命名空间你就得提一下。