2010-07-29 115 views
12

當用戶沒有登錄時,我試圖進入驗證用戶的網站區域,只有我應該被重定向到我的登錄站點?next=,這裏是我的LOGIN_REDIRECT_URL設置。但是在我的地址欄中顯示的不是/users/login而是。我應該改變什麼來獲得正確的網址?Django身份驗證 - 錯誤的重定向url登錄頁面

設置:

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'), 
          ) 

如果我應該粘貼更多,告訴我。

回答

23

您需要設置設置LOGIN_URL還有:

LOGIN_URL = '/user/login' 
+0

現在我:'HTTP://域名/用戶/資料/下一= /用戶/資料/%3Fnext%3D /用戶/ profile /%253Fnext%253D/user/profile /%25253 ...':/ – 2010-07-29 23:40:27

+0

LOGIN_URL應該是「/ user/login」而不是「/ user/profile」..錯過了你的問題。上面更新。 – ars 2010-07-29 23:56:09

相關問題