welcome: please sign in

The following 379 words could not be found in the dictionary of 7 words (including 7 LocalSpellingWords) and are highlighted below:
able   abroad   absolute   access   Add   add   address   Admin   admin   afs   aka   Alias   alias   all   Allow   allow   allowed   already   Also   also   an   and   Apache   apache   apacheconf   application   applications   appropriate   apxs   as   at   automatically   autorisation   available   bash   be   been   bin   bit   build   but   can   care   Category   caution   Cherry   Choose   code   com   commands   compiling   complex   conf   configuration   configure   Configuring   Contents   correct   couple   cp   cpserver   Create   create   created   current   daemon   database   db   default   defaults   deny   describes   did   different   directories   Directory   directory   Django   django   do   document   documentation   does   doesn   doing   Domtool   Don   don   download   Download   easier   easy   emphasize   enable   enter   entry   environment   error   errors   eth0   everything   example   expose   familiar   far   favicon   Feel   file   files   fine   firewall   First   follow   followsymlinks   For   for   forget   forgot   Fortunaly   forward   found   Framework   free   freeze   from   fsr   Go   good   google   great   gz   have   hcoop   help   high   highlight   Home   home   http   httpd   ico   identify   If   ifconfig   img   important   improved   in   include   included   including   information   install   installation   installations   installed   instead   instructions   integrate   integrates   Integration   interpreter   ip   is   issue   it   It   itself   Just   k5start   latest   link   Links   Listen   Lite   little   ll   Load   local   location   log   long   make   makes   manage   Manual   media   Member   mod   Module   module   modules   modwsgi   more   More   must   My   my   na   nachtdier   necessary   need   Needs   net   never   new   nicely   no   normal   not   Notice   notice   now   Of   of   ofcourse   On   on   one   Only   only   open   option   Order   org   organize   Other   other   overwrite   Own   own   packages   page   pages   parameter   part   path   pip   pkg   place   point   popular   ports   prefer   prefix   probably   process   production   project   proper   Push   put   Py   py   pypi   python   Python2   python2   quite   re   realize   really   reason   reasonable   requirement   rewrite   root   run   running   Running   runserver   same   sbin   script   Script   seen   separate   Server   server   serving   Serving   set   setacl   settings   Settings   setup   shortcoming   should   shows   Simple   simple   site   So   so   solved   some   something   somewhere   source   special   specific   Squeeze   static   Static   steps   straight   subdirectory   suggest   Support   sure   sw   switch   symbolic   Table   tar   test   that   The   the   them   then   Therefore   These   these   things   this   This   through   to   too   tool   tools   tricky   txt   type   unattended   under   understand   Unfortunaly   unix   Unix   unless   updated   use   Use   user   uses   Using   ve   version   very   via   virtual   Virtualenv   virtualenv   want   was   Web   web   webserver   well   wget   which   wiki   will   With   with   work   Work   works   wsgi   www   You   you   Your   your   yourrequirements   yourself   zxfv  

Clear message

MemberManual / WebApplications / Django

These instructions have not been updated for Debian Squeeze. The process is probably easier now, and this page should be updated.

1. Serving Django

Running your own Apache, mod_wsgi and Django on HCOOP is reasonable easy. You must realize that you're not doing a server installation, but a local (aka your own home-directory) installation. Apache don't care, as long as you enter the correct configuration.

The only tricky part is Virtualenv. You need this popular Python tool to create a your own Django environment. Using Virtualenv is straight forward. Unfortunaly, Virtualenv makes the installation and configuration of your other tools a little bit more complex. Therefore, I created this page to help you through these steps.

1.1. Apache http server

Download the latest version from http://apache.org. Choose for unix source and build your Apache yourself. If you follow the instructions, then it is quite simple. Don't forget to include the mod_rewrite module in your build. Also, don't do /apache which you're not allowed on HCOOP, but $HOME/apache. Also, notice that I use $HOME. For some reason ~/apache doesn't work with configure but $HOME works fine.

./configure --prefix=$HOME/sw/pkg/apache --enable-rewrite
make install

More information is on RunningYourOwnApache.


Just download the source, follow the instructions and you'll be fine. The documentation emphasize that use the same python version for compiling, as well as running. This is a good reason to overwrite the defaults and point to the python that you want. I want version 2.5 in a Virtualenv environment. $YOURVIRTUALENV/bin/python is a 2.5 interpreter. Notice that I will use this environment for compiling mod_wsgi, as well as running mod_wsgi with the proper instructions in httpd.conf.

./configure --with-apxs=$HOME/$YOURAPACHE/bin/apxs --with-python=$HOME/$YOURVIRTUALENV/bin/python
make install

1.3. httpd.conf

1.3.1. Server

   1 Listen 8172
   3 #not required if built-in
   4 #LoadModule rewrite_module modules/mod_rewrite.so
   5 LoadModule wsgi_module modules/mod_wsgi.so

1.3.2. Static media

You need to organize a couple of things in the Apache configuration file. First of all, you want an alias for your "favicon.ico". With a static web-site the favicon is in the document root. I prefer the favicon in the same directory as my other static media. Therefore you need an alias for the directory with your static media, as well as an alias for your favicon. Don't forget to add the Directory entry for this directory.

   1 alias /favicon.ico /$YOURPROJECT/site_media/favicon.ico
   2 alias /site_media/ /$YOURPROJECT/site_media/

For the Admin part of your Django project you will probably use the default Django admin pages and media files. Add a symbolic link to your Django directory (don't forget to add followsymlinks to your Apache configuration) and configure that one too.

   1 alias /media/ /$YOURPROJECT/media/

1.3.3. WSGI & Django

   1 WSGIPythonHome /afs/hcoop.net/user/n/na/nachtdier/$YOURVIRTUALENV
   3 Alias /favicon.ico /afs/hcoop.net/user/n/na/nachtdier/$YOURDJANGO/site_media/img/favicon.ico
   4 Alias /site_media/ /afs/hcoop.net/user/n/na/nachtdier/$YOURDJANGO/site_media/
   6 <Directory /afs/hcoop.net/user/n/na/nachtdier/$YOURDJANGO/site_media>
   7   Order allow,deny
   8   Allow from all
   9 </Directory>
  11 Alias /media/ /afs/hcoop.net/user/n/na/nachtdier/$YOURDJANGO/media/
  13 <Directory /afs/hcoop.net/user/n/na/nachtdier/$YOURDJANGO/media>
  14   Order allow,deny
  15   Allow from all
  16 </Directory>
  18 WSGIScriptAlias / /afs/hcoop.net/user/n/na/nachtdier/$YOURDJANGO/apache/django.wsgi
  20 <Directory /afs/hcoop.net/user/n/na/nachtdier/$YOURDJANGO/apache>
  21   Order allow,deny
  22   Allow from all
  23 </Directory>

1.4. AFS

On HCOOP, one should not use the normal Unix autorisation, but AFS instead. RunningYourOwnApache describes the necessary part for Apache (e.g. k5start). You must do the part of your application yourself. Notice that the autorisation is for USER.daemon instead of USER.

So far, I've found that one must set the proper autorisation for Apache itself, your virtualenv directory with Python and your Django directory. My current setup is the same autorisation for USER.daemon for all directories. Feel free to suggest a more specific setup on this page.

fsr setacl $YOURAPACHE nachtdier.daemon all
fsr setacl $YOURVIRTUALENV nachtdier.daemon all
fsr setacl $YOURDJANGO nachtdier.daemon all

2. Configuring Django

2.1. WSGI

You need to have a special WSGI script in your Django project. Don't put this one in the same directory as your settings file but use a subdirectory. Only then you can enter a separate Directory with the appropriate allow and deny. You don't want to expose your directory with your settings file.

2.2. Settings.py

It is very important to understand that an unattended, production Apache is really something different from ./manage.py runserver. For example, you must use an absolute path for the location of your SQLite database instead of the more familiar "django.db". Fortunaly, the Apache error_log shows this type of errors.

3. Other information

3.1. Simple test

For simple test installations, it's easy: Django for Python2.5 is already installed, and (unless some new firewall is in place,) you can open high ports and access them from abroad via ip address (use /sbin/ifconfig eth0 to identify IP address.)

Django's webserver can be seen with:

python manage.py runserver

3.2. Virtualenv

Virtualenv is not available in the python installation on HCOOP. You must download (wget) the script yourself and put it somewhere under your home directory.

   1 $ wget http://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.1.tar.gz
   2 $ tar zxfv virtualenv-1.1.tar.gz 
   3 $ cp virtualenv-1.1/virtualenv.py ./

The environment that you create does include PIP. PIP is the new and improved easy_install. The option "freeze" works great with HCOOP. Create your Python environment (including Django ofcourse) on your home PC. Create the requirement file with 'pip freeze > yourrequirements.txt'. Push that file to HCOOP. Go to the bin directory in your environment. Use 'pip install -r yourrequirements.txt' and automatically everything is installed in that environment.

Virtualenv uses the default python interpreter for the virtual environment. On HCOOP the default is version 2.4. Support for SQLite is included in 2.5, so I prefer that version for Django. Python 2.5 is also available on HCOOP. Use the parameter -p python2.5 and that version will be installed in your environment. Don't forgot to use that version for mod_wsgi too.

   1 ./virtualenv.py -p python2.5 --no-site-packages $YOURVIRTUALENV

3.4. Django_cpserver

The application CherryPy is also very good in serving Python applications. CherryPy is also a Web Framework, but you can use it for serving only. The Django application cpserver integrates CherryPy nicely in Django with Django commands. It did run great at home and HCOOP. Unfortunaly I was never able to integrate it with the mod_rewrite in the Domtool. I'm quite sure it was my shortcoming. I solved the issue with a switch to mod_wsgi.

CategoryMemberManual CategoryNeedsWork

MemberManual/WebApplications/Django (last edited 2013-01-14 07:17:48 by ClintonEbadi)