2010-07-29 12 views
12

Quando un utente non è loggato Sto provando ad entrare nelle aree del sito solo per utenti autenticati Devo essere reindirizzato al mio sito di login con ?next= e qui il mio LOGIN_REDIRECT_URL dalle impostazioni. Ma invece di /users/login nella mia barra degli indirizzi /accounts/login viene visualizzato. Cosa dovrei cambiare per ottenere l'url giusto?Autenticazione Django - URL di reindirizzamento errato alla pagina di login

impostazioni: URL

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

del progetto:

import accounts.urls as regUrls 

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

conti urls.py applicazione:

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

e conti auth_urls.py (che sono URL semplicemente per 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'), 
          ) 

Se dovessi incollare qualcosa di più, dimmelo.

risposta

23

È necessario impostare la LOGIN_URL nelle impostazioni così:

LOGIN_URL = '/user/login' 
+0

ora ho: 'http: // dominio/user/profile/successivo =/user/profile /% 3Fnext% 3D/utente/profile /% 253Fnext% 253D/user/profile /% 25253 ... ':/ –

+0

Il LOGIN_URL avrebbe dovuto essere"/user/login "non"/utente/profilo ".. perso nella tua domanda. Aggiornato sopra. – ars

Problemi correlati