Jacques Mattheij

Technology, Coding and Business

installing django on debian etch based server

Notes on installing django 1.0 on Debian Etch 64 bit, using mod_wsgi

install the apache dev package

apt-get install apache2-threaded-dev

upgrade python to v 2.5

apt-get install python2.5 apt-get install python2.5-dev

rm /usr/bin/python ln -s /usr/bin/python2.5 /usr/bin/python

make a django directory

mkdir /home/django cd /home/django

install mysql python bindings

mkdir mysql cd mysql wget http://voxel.dl.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.2.tar.gz tar -zxvf MySQL-python* cd MySQL-python* python setup.py build python setup.py install cd ..

get, build and install mod_wsgi

wget http://modwsgi.googlecode.com/files/mod_wsgi-2.5.tar.gz

gzip -d *.gz tar xvf *.tar

cd mod_wsgi-2.5 ./configure

make

make install

echo LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so > /etc/apache2/mods-enables/wsgi.load

cd /home/projects/django

wget http://www.djangoproject.com/download/1.1/tarball/

gzip -d Django*.gz

tar xf Django*.tar

cd Django-1.1

python setup.py install

cd ..

cat > django.wsgi import os, sys sys.path.append(‘/home/projects/django’) os.environ[‘DJANGO_SETTINGS_MODULE’] = ‘f5news.settings’

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

ctrl-d

‘f5news’ and ‘/home/projects/django’ to be replaced with whatever is appropriate

add something like this to your httpd.conf

ServerName django.f5news.com

Alias /images/ /home/projects/django/f5news/images/

Order deny,allow Allow from all

WSGIScriptAlias / /home/projects/django/f5news/django.wsgi

Order deny,allow Allow from all

cd /home/projects/django

make project

django-admin.py startproject f5news

cd f5news

vi settings.py

add database settings and so on

mysqladmin create newdbname

grant privilige to alter tables and index to user www-data

cd ..

python manage.py syncdb

create a super user and set a password

create application

python f5news/manage.py startapp polls

cd polls

edit models.py like this:

from django.db import models

class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField(‘date published’)

def __unicode__(self):
    return self.question

class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(max_length=200) votes = models.IntegerField()

def __unicode__(self):
    return self.choice

from f5news.polls.models import Poll, Choice
import datetime
p = Poll(question=“What’s up?”, pub_date=datetime.datetime.now()) p.save()
p.id
1L
p.question
“What’s up?”
p.pub_date
datetime.datetime(2009, 8, 13, 13, 3, 44, 446513)
Poll.objects.all()
[]

Poll.objects.get(pub_dateyear=2009) p = Poll.objects.get(pk=1) p.choice_set.create(choice=‘Not much’, votes=0) p.choice_set.create(choice=‘The sky’, votes=0) c = p.choice_set.create(choice=‘Just hacking again’, votes=0) c.poll p.choice_set.all() [, , ] p.choice_set.count() 3 Choice.objects.filter(pollpub_dateyear=2007) [] Choice.objects.filter(pollpub_date__year=2009) [, , ]

from here the tutorial takes over:

http://docs.djangoproject.com/en/dev/intro/tutorial01/#intro-tutorial01

python manage.py syncdb

python manage.py runserver 0.0.0.0:8080

from f5news.polls.models import Poll, Choice import datetime p = Poll(question=“What’s up?”, pub_date=datetime.datetime.now()) p.save() p.id 1L p.question “What’s up?” p.pub_date datetime.datetime(2009, 8, 13, 13, 3, 44, 446513) p.pub_date = datetime.datetime(2007, 4, 1, 0, 0) Poll.objects.all() []

something was wrong in the pythong config to allow it to load the mysql bindings for python, this fixed it:

/.python-eggs/MySQL_python-1.2.2-py2.5-linux-x86_64.egg-tmp/_mysql.so

Make it accessible

HN Submission/Discussion
If you read this far you should probably follow me on twitter: