Django logo
Django logo (Photo credit: Wikipedia)

.Django creates automatically a web admin portal for our web app. We just have to edit the settings.py file and to uncomment “django.contrib.admin” in the INSTALLED_APPS setting.

    # Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs', 
 

We need to update the database to take into account the new apps. But first, we will check if we have the latest version of Django.

sudo easy_install --upgrade django
chmod +x manage.py
./manage.py syncdb

If we have a look to our django powered website, we will see that it is still empty, because we have not defined any url for the moment:

./manage.py runserver
firefox http://127.0.0.1:8000/

Let’s define the URLs by editing the urls.py file and uncommenting all lines related to the admin and admin documentation:

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

(...)

# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),

Now, our admin site is ready:

firefox http://127.0.0.1:8000/admin/

If you do not remember the admin password that you setup in part 2 of this tutorial (the login is root), then create a new one.

The admin portal does not display our application textModif. We have to go to textModif folder and add a file admin.py there:

cd textModif
vim admin.py

We put the following lines in this file:

from django.contrib import admin
from textModif.models import *

admin.site.register(TextTask)
admin.site.register(TextOperation)
admin.site.register(TextModification)

We restart the server to see the changes (kill the associated process if you have maintained the server):

./manage.py runserver
firefox http://127.0.0.1:8000/admin

Now we can edit our data structure through the web administration interface. Django’s official tutorial shows also how to customize very easily the admin interface. We will skip this part, as I would like to focus on our web app’s frontend implementation.


Leave a Reply

Your email address will not be published. Required fields are marked *