Friday, February 10, 2012

Checklist for enabling Authentication in Django

1. Ensure that following session and authentication middleware exists in settings.py
'django.contrib.sessions.middleware.SessionMiddleware'
2. Ensure that following session and authentication apps exists in settings.py
'django.contrib.sessions'
3. Add paths for login and logout in urls.py (the paths can also be different from those shown below)
('^accounts/login/$', login),
('^accounts/logout/$', logout),
4. Create html pages for login and logout at registration/login.html and registration/loggout_out.html
5. Be sure to put the csrf protection tag inside the login form
6. Be sure that you have at least one user account created (which you most likely will have at this point)
7. Add the login_required decorator to any view function
8. If you need to access the request object in your templates, add TEMPLATE_CONTEXT_PROCESSORS to settings.py
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.request',
)

No comments:

Post a Comment