We use Django at work because it makes the development and maintenance phases of development so fast, easy and pleasant, but I can tell you that the deployment of those applications is a pain in the ass. We need to use three different .htaccess files to make our applications work correctly and every time we make a modification to a Python file, we need to restart Apache (we know the hosting company we do business with well, and they agreed to let us have root access.) PHP may be a pain to work with, but at least deployment is a simple upload.
Without going into too much details, on the hosting server, clients have a folder with a bunch of subfolders in it, one of which is httpdocs/. This is the root of their web site. Because our skeleton project (see previous blog post) is called ‘wsf’, we need a way to redirect from http://foo.com/ to http://foo.com/wsf/. That’s what our first .htaccess file is for:
RewriteEngine on RewriteBase / RewriteRule ^$ wsf/
This file is located directly in httpdocs. Then, we need to tell Apache that wsf/ is a Django project, so we have a second .htaccess file in httpdocs/wsf:
SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE wsf.settings PythonInterpreter client_name PythonPath "['/var/www/vhosts/foo.com/httpdocs'] + sys.path" PythonDebug Off
And finally, we have the media files in httpdocs/wsf/media. I begin by making a symlink in httpdocs (ln -s httpdocs/wsf/media .) and in that directory, I need to put the third .htaccess file:
Django is an absolutely fantastic way to develop web sites and applications, but it’s a terrible way to deploy them. I think one of PHP’s greatest strengths (some might call it a downside) is that it’s extremely easy for somebody to write a script and get it working online. We get excited about Django, we get people interested, but when they ask the simple question “how do I get this online?”, our answer is “hmmm, that’s pretty complex…” It shouldn’t be.
A few weeks ago on the FLOSS Weekly podcast, Leo Laporte and Randal Schwartz were interviewing Avi Bryant of Seaside fame. Randal and Avi were both super excited about Smalltalk, Squeak and Seaside, so Leo downloaded Squeak during the show, booted it up and asked the question “How do I write ‘Hello world’?” And at this point, I swear I heard Avi and Randal say “fuck” in their heads. A similar silenced “fuck” came about when Leo asked how to install Seaside. I always found deployment in Smalltalk to be a hassle, and I guess just getting something to work easily isn’t its strong suit. Web frameworks should not be like this.
There needs to be more work done in that area with Django and other frameworks. We need to be able to just upload a project and have it work easily and painlessly. There should be no need to restart Apache when you make a modification to a Python file. You shouldn’t have to edit httpd.conf or .htaccess to get your application working (an initial setup in httpd.conf to enable Django support in general is acceptable.) Root access should not be a required to get a Django application up and running. (Technically, root access isn’t required, but you won’t find a lot of hosts that don’t mind you restarting their services.)
I vaguely remember trying the Symfony PHP framework, which was partly inspired by Rails. I do not recall having to make any special configuration in httpd.conf to get it working. Maybe Django and Rails should look in that direction for tips on how to get things working.