From MetaWiki
Jump to: navigation, search

(See also: Artenquiz documentation)


Install automatically

Under Debian 6, Squeeze

#default version is 1.2:
sudo apt-get update # get updated package data
apt-cache showpkg python-django # check version
sudo apt-get install python-django python-django-registration python-mysqldb
# Instead, it is possible to install 1.3.1 from squeeze backport - WE DID THIS:
sudo apt-get remove python-django
sudo apt-get -t squeeze-backports install python-django  python-django-registration
# Result was: Setting up python-django (1.3.1-2~bpo60+1)

Advantage of debian repository installation is that apt-get update will inject any necessary security updates.

NOTE: python-django-registration is NOT in a current version, but in an older one than we used before. Debian has only 0.7.x, we had used 0.8alpha. Thus: sudo apt-get remove python-django-registration and installed manually!

Use Python pip

Use alternative python package installer (instead of easy_install):

sudo apt-get update # get updated package data
sudo apt-get install python-pip
# first install or install a specific version
pip install django==1.4.2
# upgrade: there is a upgrade option and may work, or deinstall and reinstall it
pip uninstall django
pip install django==1.5


link =

Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.

Version in lenny is 1.0, which is too old.

# Download 
mkdir ~/temp
cd ~/temp
# extract
tar xzvf Django-1.2.5.tar.gz
# install (see
cd ./Django-1.2.5
sudo python install --prefix /usr/local
# Install mod_wsgi for Apache (it is enabled automatically):
apt-get install libapache2-mod-wsgi

To use this version with the application “artenquiz”, add an apache virtual host (see /etc/apache2/sites-enabled/artenquiz).

Install/Upgrade by script

Using the following bash script you can upgrade django to a certain version, here 1.3. It tries to download that version and optionally delete the old one first. For more details see also

# define a version
#get directories
SITEPACKAGESDIRLOCAL=`python -c "from distutils.sysconfig import get_python_lib; print get_python_lib(0, 0, '/usr/local')"`
SITEPACKAGESDIR=`python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"`
echo "Remove older django first?"
select yn in "Yes" "No"; do
    case $yn in
        Yes ) echo "Remove django..."; 
          sudo rm -r Django*
          sudo rm -r django*
          sudo rm -i /usr/local/bin/
          sudo rm -i $SITEPACKAGESDIR/django.pth
        No ) break;;
echo "Download django $djversion and install?"
select yn in "Yes" "No"; do
    case $yn in
        Yes ) 
          echo "Download django..."; 
          # download
            wget "$djversion/tarball/" --output-document=Django-${djversion}.tar.gz
            if [ -a Django-${djversion}.tar.gz ]; then
              # extract
              tar xzf Django-${djversion}.tar.gz
                cd Django-${djversion}
              echo "Django extracted to ./Django-${djversion}"; 
              echo "Install to ${SITEPACKAGESDIRLOCAL}..."; 
              # install
              sudo python install --prefix /usr/local
              # some information
              echo "**************************************"
              echo "Files are in:"
              echo ${SITEPACKAGESDIRLOCAL}
              echo ${SITEPACKAGESDIR}
              echo "/usr/local/bin/"
              echo "**************************************"
              echo "Could not download Django-${djversion}.tar.gz. Stop."
            fi # end Django-${djversion}.tar.gz
        No ) echo "Exit."; exit;;

Reloading Source Code

The mod_wsgi is an extra layer additionally to the apache. Usually when there is any code change on py-files it will reload. However sometimes it does not. Further reading:


Management tasks

cd $djangoPath
# get help infos
  python help
  python help createsuperuser
# create a superuser
  python createsuperuser
# show django’s default database model descriptions based on the database in
  python inspectdb
# run developement server on
  python runserver
# get python shell for django
  python shell
# start a project help startproject mysite 
# create an application help startapp myapp # in the current directory

Directory architecture

├─ apache/
│  └─ django.wsgi  mod_wsgi interface between webserver and Python applications
├─ yourapp/
│  ├─  model definitions
│  ├─   admin GUI settings
│  └─   view layer definitions
├─ locale/  localized application messages for internationalisation
│  ├─ de/LC_MESSAGES/
│  │     ├─ django.po   string dictionary for German. Created with: makemessages -l de
│  │     └─   machine readable output. Created with: compilemessages
│  ├─ en/LC_MESSAGES/
│  │     ├─ …
│  │     └─ …
│  └─  …/LC_MESSAGES/
├─ templates/  organizing HTML templates here
│  ├─ base.html
│  └─ quiz.html
├─    management tasks
├─  the program’s settings
└─      settings of url patterns

Install django-registration

Version 0.7

sudo easy_install django-registration
# uninstall
sudo easy_install -m django-registration
cd /usr/lib/python2.5/site-packages/
sudo rm django_registration-0.7-py2.5.egg

Version 0.8 alpha will install into /usr/local/lib/python2.5/site-packages/ using --prefix /usr/local

tar zxvf django-registration-0.8-*.tar.gz
cd django-registration-0.8-alpha/
sudo python install --prefix /usr/local

Admin UI

If you have created a super user account by:

  cd $djangoPath
  # get help infos
  #  python help createsuperuser
  # create a superuser
  python createsuperuser

You have access now to http://your-website/admin. Which data base models are shown, is set in

└─ yourapp/
   └─   admin GUI settings

Apache Configuration

  • create alias also for /admin UI
sudo vi /etc/apache2/sites-available/mysite
# apache config mysite alias
        WSGIScriptAlias / /path/to/django/app/django-wsgi-handler.wsgi
        Alias /static/admin/ /usr/share/pyshared/django/contrib/admin/static/admin/
        Alias /static/ /path/to/django/app/static/
        Alias /favicon.ico /path/to/django/app/static/img/favicon.ico

Additional useful software

  • python-docutils: enables the automatic generation of python code documentation that appears then in the Django admin user web-interface. A great help for administrators or programmers.
Personal tools