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

Checklist for enabling the Admin interface in Django

1. Make sure you have the following apps in INSTALLED_APPS
'django.contrib.admin'
'django.contrib.auth'
'django.contrib.contenttypes'
'django.contrib.sessions'

2. Make sure you have the following in MiddleWare
django.middleware.common.CommonMiddleware'
'django.contrib.sessions.middleware.SessionMiddleware'
'django.contrib.auth.middleware.AuthenticationMiddleware'

3. Add the admin site to URLConf
4. Ensure urls.py imports admin
5. Ensure autodiscover is on in urls.py
6. Add your models to the admin site by updating admin.py in your app directorie(s)
admin.site.register(Publisher)
...
7. python manage.py syncdb
8. Create the superuser when asked
9. Run the website and check

Checklist for creating models in Django

1. Create an app
2. Add model class to models.py in the app
3. Add the app to installed apps
4. Validate your model
python manage.py validate
5. Check the SQL which will be generated
python manage.py sqlall app_name
6. Create the tables in the db
python manage.py syncdb

Checklist for enabling databases in Django

1. Update the DATABASES section in settings.py with details of your database
2. Test the connection
>>> from django.db import connection
>>> cursor = connection.cursor()