Install Django in shared host...

The next step (after the Python 2.6 discovered) is to install Django in my shared host.

Naturally my user account is not a sudoers and I don't have the root password, so the installation using the server package system is not possible.

Fortunately any Python project is quite simple to install, and Django is a Python project :D

 wget http://www.djangoproject.com/download/1.3/tarball/
tar xzvf Django-1.3.tar.gz
cd Django-1.3
python2.6 setup.py install --user

Note: I used python2.6 command to show out I want to install and use it with that version of Python. Naturally if you have an alias python should be sufficient. Same thing if you want to install it using Python 2.4, in this case the --user option does not work, so the right command to run is

 python setup.py install --home $HOME/.local

Then, add yur Django installation to your user PATH, setting it in .bashrc file. In your home folder run:

 vi .bashrc
export PATH=$HOME/.local/bin:$HOME/.local/usr/bin:$PATH
After this two simple steps Django is ready and you can create your first project (or install your existing project).
Supposing you have your Django project installed into ~/projects/kermit-webui to make it accessible from browser you need two components configured. The first thing is a Python fastcgi script to load your Django application, the second thing is the .htaccess file to configure your Apache and load the script.
First of all we create the public_html folder where we put our two components
 mkdir ~/public_html/kermit
cd ~/public_html/kermit
Here we will create the fastcgi script
 vi kermit.fcgi

!/usr/bin/python2.6

import sys, os

Add a custom Python path.

sys.path.insert(0, "/home/user/.local/lib/python2.6")

sys.path.insert(13, "/home/user/projects/kermit")

os.environ['DJANGO_SETTINGS_MODULE'] = "webui.settings"

from django.core.servers.fastcgi import runfastcgi

runfastcgi(method="threaded", daemonize="false")


At the end of the script, as you can see, we start the fastcgi listener, to accept incoming requests.

Now we are ready to configure the .htaccess file
 vi .htaccess

AddHandler fcgid-script .fcgi

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_URI} !=/favicon.ico

RewriteCond %{REQUEST_URI} !^/static/

RewriteRule ^(.*)$ kermit.fcgi/$1 [QSA,L]

Basically we are configuring the Apache RewriteEngine, saying that all requests sould be sent to kermit.fcgi script except requests with /static/ in the url (my static file, like css, imgs, js, ... are there) and favicon.ico.

This script should have 755 access rule, so:
 chmod 0755 kermit.fcgi
And that's "all". Depending on your hosting and projects could be necessary to install some other packages. On BlueHost to use Django with fastcgi you need to install flup project.
 $ wget http://www.saddi.com/software/flup/dist/flup-1.0.2.tar.gz
$ tar xzvf flup-1.0.2.tar.gz
$ cd flup-1.0.2

Like shown before, for Python 2.6/2.7:

 $ python setup.py install --user

For previous versions:

 $ python setup.py install --home $HOME/.local
Now you can browse your django application :D

If you want to see a first result of this test, point your browser on http://kermit.mornati.net