Django身份验证-错误的将URL重定向到登录页面 [英] Django authentication - wrong redirect url to login page

查看:256
本文介绍了Django身份验证-错误的将URL重定向到登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户未登录时,我只尝试输入经过身份验证的用户的站点区域,我应该使用?next = 重定向到我的登录站点,这里是我的设置中的LOGIN_REDIRECT_URL。但是,在我的地址栏中没有显示 / users / login ,而是显示了 / accounts / login 。我该如何更改才能获得正确的网址?

When a user is not logged I'm trying to enter areas of site for authenticated users only I should be redirected to my login site with ?next= and here my LOGIN_REDIRECT_URL from settings. But instead of /users/login in my address bar /accounts/login is displayed. What should I change to get the right url ?

设置:

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

项目的网址:

import accounts.urls as regUrls

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

帐户应用程序urls.py:

accounts application 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):

and accounts auth_urls.py (which are simply urls for 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'),
                           )

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

If i should paste anytning more, just tell me.

解决方案

您需要设置设置中的 LOGIN_URL

You need to set the LOGIN_URL in settings as well:

LOGIN_URL = '/user/login'

这篇关于Django身份验证-错误的将URL重定向到登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆