Django-Installation
(See also: Artenquiz documentation)
Contents |
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!
Manually
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 wget http://www.djangoproject.com/download/1.2.5/tarball/ # extract tar xzvf Django-1.2.5.tar.gz # install (see http://docs.djangoproject.com/en/1.2/topics/install/#installing-official-release) cd ./Django-1.2.5 sudo python setup.py 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 http://docs.djangoproject.com/en/dev/topics/install/#how-to-install-django
#!/bin/bash # define a version djversion=1.3 #get directories #SITEPACKAGESDIRLOCAL=/usr/local/lib/python2.5/site-packages 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..."; cd $SITEPACKAGESDIRLOCAL sudo rm -r Django* sudo rm -r django* sudo rm -i /usr/local/bin/django-admin.py sudo rm -i $SITEPACKAGESDIR/django.pth break;; No ) break;; esac done echo "Download django $djversion and install?" select yn in "Yes" "No"; do case $yn in Yes ) echo "Download django..."; # download wget "http://www.djangoproject.com/download/$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 setup.py install --prefix /usr/local # some information echo "**************************************" echo "Files are in:" echo ${SITEPACKAGESDIRLOCAL} echo ${SITEPACKAGESDIR} echo "/usr/local/bin/django-admin.py" echo "**************************************" else echo "Could not download Django-${djversion}.tar.gz. Stop." exit fi # end Django-${djversion}.tar.gz break;; No ) echo "Exit."; exit;; esac done
Miscellaneous
Management tasks
djangoPath=/to/my/django/application/ cd $djangoPath # get help infos python manage.py help python manage.py help createsuperuser # create a superuser python manage.py createsuperuser # show django’s default database model descriptions based on the database in settings.py python manage.py inspectdb # run developement server on http://127.0.0.1:8000/ python manage.py runserver # get python shell for django python manage.py shell # start a project django-admin.py help django-admin.py startproject mysite # create an application django-admin.py help django-admin.py startapp myapp # in the current directory
Directory architecture
django-project-root ├─ apache/ │ └─ django.wsgi mod_wsgi interface between webserver and Python applications │ ├─ yourapp/ │ ├─ models.py model definitions │ ├─ admin.py admin GUI settings │ └─ views.py view layer definitions │ ├─ locale/ localized application messages for internationalisation │ ├─ de/LC_MESSAGES/ │ │ ├─ django.po string dictionary for German. Created with: django-admin.py makemessages -l de │ │ └─ django.mo machine readable output. Created with: django-admin.py compilemessages │ ├─ en/LC_MESSAGES/ │ │ ├─ … │ │ └─ … │ └─ …/LC_MESSAGES/ │ ├─ templates/ organizing HTML templates here │ ├─ base.html │ └─ quiz.html │ ├─ manage.py management tasks ├─ settings.py the program’s settings └─ urls.py 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
wget https://bitbucket.org/ubernostrum/django-registration/downloads/django-registration-0.8-alpha-1.tar.gz tar zxvf django-registration-0.8-*.tar.gz cd django-registration-0.8-alpha/ sudo python setup.py install --prefix /usr/local
Admin UI
If you have created a super user account by:
djangoPath=/to/my/django/application/ cd $djangoPath # get help infos # python manage.py help createsuperuser # create a superuser python manage.py createsuperuser
You have access now to http://your-website/admin. Which data base models are shown, is set in
django-project-root
└─ yourapp/
└─ admin.py admin GUI settings