From Wordpress to Django

I made the jump and since last night this blog is powered by Django.

There's no particular reason for the move; Wordpress is a very capable blogging platform (probably the leader at this point) and the only thing that was bothering me was the frequent security warnings where basically you have to keep the software updated to the latest version (although this is pretty straight-forward) and some details like still receiving spam even if I have the comments deactivated.

I've been playing with Python and Django for a while and it seems that a rite of passage for Pythonistas is creating your own web framework, but I set a much humbler goal to do within a few hours: porting the basic Wordpress functionality using Django. Actually is not a "port" but having a basic blog (I don't use special or fancy plug-ins etc, I just want the barebones) reusing Wordpress' database and one of its templates.

Coding with Django has been a breeze; you accomplish a lot with very few lines of code. The Django data model was created from inspection of the WP database, I only had to insert timestamps in a couple of fields where the introspection tool stumbled. I tried to defined foreign keys in the model but it didn't work. In any case I'll be using in the future a new leaner database schema and that will simplify my code (for example the relationship between posts and topics is many-to-many, so besides tables for topics and posts we need another one. WP uses a fourth one) and I'll also be able to use the foreign keys in the code.

Django is great for migrations since you can have its code anywhere and use its url matching to take charge of handling url requests to the old application. For example I have my Wordpress application under a "/wordpress" directory and just by switching on a directive in Apache Django can take over it (I made it a little more complicated by changing the main blog directory name with great imagination to 'blog').

I still need to add some more functionality: more views (archives etc), search, RSS feed and perhaps comments. My prejudice is that the new app will be more secure since the main entry point is now just Django's admin tool.

After having a prototype running with the built-in Django development server I moved to Apache, and here's were I spent most of the time. I had a weird problem where Django under Apache was working (kind of), it will give me its 404 error page if I went to a page not defined in my urls.py but the pages will show up blank.

Finally after narrowing down the problem I get an error: "ImproperlyConfigured: Error importing middleware django.contrib.sessions.middleware MySQLdb-1.2.1p2 or newer is required", this was kind of funny because the development server never complained. I tried setting 'mysql-old' instead of mysql in the settings only to get some other error. So I downloaded mysql-python 1.2.2 and when I tried to install it, I had a complaint about the version of setuptools, so I downloaded the latest version of it as well, and after uninstalling older stuff, setting the egg path in Apache, doing a magic dance to the moon and some fiddling around I got it all working.