Django身份验证 - 错误的重定向URL到登录页面

时间:2010-07-29 23:31:00

标签: django redirect django-authentication

当用户未登录时,我正在尝试为经过身份验证的用户输入站点区域,我应该将{/ 1}}重定向到我的登录站点,并从设置重定向到我的LOGIN_REDIRECT_URL。但是,我的地址栏?next=中显示/users/login而不是/accounts/login。我应该更改什么才能获得正确的网址?

设置:

AUTH_PROFILE_MODULE = 'accounts.UserProfile'
LOGIN_REDIRECT_URL = '/user/profile/'

项目的网址:

import accounts.urls as regUrls

urlpatterns = patterns("",
                        (...)                     
                        (r'^user/', include(regUrls)),                       
                        )

帐户应用urls.py:

urlpatterns = patterns('',
                       url(r'^profile/$', profile_edit , name='user_profile'),
                       url(r'^friends_list/$', friends_list),
                       (r'', include('accounts.auth_urls')),
                       )

和帐户auth_urls.py(这只是contrib.auth的网址):

from django.conf.urls.defaults import *
from django.views.generic.simple import direct_to_template
from django.contrib.auth import views as auth_views

    urlpatterns = patterns('',
                           url(r'^login/$',
                               auth_views.login,
                               {'template_name': 'user/login_logout_register/login.html'},
                               name='auth_login'),
                           url(r'^logout/$',
                               auth_views.logout,
                               {'template_name': 'user/login_logout_register/logout.html'},
                               name='auth_logout'),                     
                           url(r'^password/change/$',
                               auth_views.password_change,
                               {'template_name': 'user/login_logout_register/password_change_form.html'},
                               name='auth_password_change'),
                           url(r'^password/change/done/$',
                               auth_views.password_change_done,
                               {'template_name': 'user/login_logout_register/password_change_done.html'},
                               name='auth_password_change_done'),                      
                           url(r'^password/reset/$',
                               auth_views.password_reset,
                               {'template_name': 'user/login_logout_register/password_reset_form.html',
                               'email_template_name': 'user/login_logout_register/password_reset_email.html'},
                               name='auth_password_reset'),                     
                           url(r'^password/reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
                               auth_views.password_reset_confirm,
                               {'template_name': 'user/login_logout_register/password_reset_confirm.html'},
                               name='auth_password_reset_confirm'),                     
                           url(r'^password/reset/complete/$',
                               auth_views.password_reset_complete,
                               {'template_name': 'user/login_logout_register/password_reset_complete.html'},
                               name='auth_password_reset_complete'),                     
                           url(r'^password/reset/done/$',
                               auth_views.password_reset_done,
                               {'template_name': 'user/login_logout_register/password_reset_done.html'},
                               name='auth_password_reset_done'),
                           )

如果我要粘贴更多,请告诉我。

1 个答案:

答案 0 :(得分:31)

您还需要在设置中设置LOGIN_URL

LOGIN_URL = '/user/login'