N800 as Django Development Server
Django is a web application framework written in Python. Similar to Ruby on Rails, it lets you build powerful websites quickly and with minimal code.
So why would you want to get Django running on the Nokia N800, you ask? Good question.
- The n800 is a low power, quiet, always on development environment, at least for Python/Django it is.
- Django provides the means to create web-based applications that run locally for Maemo without the overhead of setting up the development Scratchbox or learning GTK
- Its just cool to have a server running off of this thing.
Anyways in my case I was learning Django by building this website which is on Dreamhost with a shared web hosting plan. Shared web hosting isn't the best environment to do testing and development on. The servers' resources are split between many users which can result in laggy ssh sessions and long load times for Django's error output. Also there's the concern of your faulty code messing with other user's resources. All in all not the best development environment.
Of course you could always develop locally off of your desktop or whatever and upload the working code to your server later. Well in my case I am dual booting between Ubuntu and Windows XP. Switching back and forth hampers my access to the my local apache install. Meanwhile my always-on n800 is sitting on my desk waiting to be put to work. All Django needs to run is a working python installation and some database. Perfect because both Python and SQLite are available on the Maemo platform. What about a web server? Well Django has a builtin server meant for development and testing purposes that utilizes Python's BasicHttpServer. Unfortunately the version of Python for the n800 is slightly stripped down. But no worries, Django can run on the Nokia with just a few extra modules borrowed from a full Python installation.
OK, I am going to assume you have most of the basic extras installed onto your tablet already, like osso-xterm, ssh, becomeroot, wget, python, pysqlite and whatever else. If not, search for them on the Maemo Application Database.
This is actually a fairly simple procedure:
- Copy cgi.py, getpass.py, and BaseHTTPServer.py usually from the /usr/lib/python2.5/site-packages/ directory of a full install of python on another machine into your Nokia's /usr/lib/python2.5/site-packages/ directory.
- Download the latest copy of Django. From the command line type: "wget http://www.djangoproject.com/download/0.96/tarball/"
- unpack it: "tar xzvf Django-0.96.tar.gz"
- give Django a place to live: "mkdir -p /home/django/django_src; mkdir /home/django/django_projects; mkdir /home/django/django_templates"
- move Django in: "cp ./Django-0.96/* /home/django/django_src/"
- now create a link to Django in your Python directory so that Python can use it: "ln -s /home/django/django_src/django /usr/lib/python2.5/site-packages/"
- Finally make a link to this script: "ln -s /home/django/django_src/django/bin/django-admin.py /usr/local/bin/"
- To check if its installed run Python and import the Django module: "python; import django" if you don't get an error message, you should be ok.
Now Django is installed. Although the actual construction of a Django app is beyond the scope of this post, to get a simple one up and running is also quite easy. The main other player in this flea circus is your database, which on maemo has to be SQLite. Assuming pysqlite is already installed to get your first app running do the following:
- cd /home/django/django_projects
- django-admin.py startproject myproject
- cd ./myproject
- edit the settings.py file. On the line that says DATABASE_ENGINE = put sqlite3 in the quotes. On the following line DATABASE_NAME = put: /home/django/django_projects/myproject/django_db in the quotes. Thats all there is to it to setting up the database. Actually creating apps and defining models that use this database is done elsewhere.
- Now at the command prompt type this to start your Django server: "python manage.py runserver 192.168.1.4:8000" replace this example ip address with that of your tablet. Then barring any error messages you should be able to access the default Django startup page from Opera by typing in the ip address and port you specified.

Comments
great article. Im buying one and doing this
You have a small typo in step 7 - the script is django-admin.py
Great tutorial - glad to know it can be done; very interested in the N800 now.
ah, nice catch. thanks :)
Thanks for the tutorial, the only thing I had to do on #7 was: make the following link: "ln -s /home/django/django_src/django/bin/django-admin.py /usr/bin/"
comments have been disabled until I get a captcha setup to stop the comment spam.