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 ?
settings :
AUTH_PROFILE_MODULE = 'accounts.UserProfile'
LOGIN_REDIRECT_URL = '/user/profile/'
project's urls :
import accounts.urls as regUrls
urlpatterns = patterns("",
(...)
(r'^user/', include(regUrls)),
)
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')),
)
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.
The Django auth app Django automatically installs the auth app when a new project is created. Look in the django_project/settings.py file under INSTALLED_APPS and you can see auth is one of several built-in apps Django has installed for us. To use the auth app we need to add it to our project-level urls.py file.
The Django authentication system handles both authentication and authorization. Briefly, authentication verifies a user is who they claim to be, and authorization determines what an authenticated user is allowed to do. Here the term authentication is used to refer to both tasks.
from django. contrib. auth import authenticate user = authenticate(username='john', password='secret') if user is not None: if user. is_active: print "You provided a correct username and password!" else: print "Your account has been disabled!" else: print "Your username and password were incorrect."
You need to set the LOGIN_URL
in settings as well:
LOGIN_URL = '/user/login'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With