Prosthetic Conscience

Jason McBrayer's weblog; occasional personal notes and commentary

Mon, 11 Jun 2007

Installing Django as CGI

When Django was first released, it was only straightforwardly possible to deploy it using mod_python, for which it was designed. However, it also soon included an adapter for WSGI, the Python standard for web application servers to interface with web servers. The WSGI interface was combined with a WSGI-fastcgi gateway called flup to make it possible to host Django applications on FastCGI, and this support eventually became fully integrated with Django. FastCGI is as fast as mod_python, and is somewhat more commonly deployed, especially on commodity shared web-hosting providers.

It is also capable of running the Django app under a different user identity from the web server, either through a suexec wrapper, or by being explicitly started as a server process by another user.

However, while FastCGI is widely deployed, it is not universally deployed, and many hosting providers that support it do so poorly. This article explains how to use the Django WSGI adapter to run Django as a pure CGI application. Performance with this method is terrible, but it might still be suitable for low volume sites on commodity hosting, and especially given adequate caching. It is also a convenient harness for testing, especially for sites to be deployed as FastCGI, and it provides the same separation of privileges from the web server that Fast CGI provides.

Installing a Django project as CGI is very similar to installing it as FastCGI. These instructions presume the use of Apache 2.x. Put this script in your cgi-bin directory. It is derived from the example cgi-wsgi gateway in PEP 333. There’s a similar implementation in Django’s ticket # 2407, but I didn’t know about this when I started writing this note. (I don’t claim any great originality for this method; I just threw together existing components and banged on them until they worked.) Adjust the paths to match where you have installed your project (outside your document root, hopefully!).

Then, you install an htaccess file like this into your DocumentRoot:

AddHandler cgi-script .cgi
RewriteEngine On
RewriteRule ^media - [L]
RewriteRule ^cgi-bin - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /cgi-bin/django.cgi/$1 [QSA,L]

This will redirect all requests under your DocumentRoot except for cgi-bin, media, and files that actually already exist, to your django cgi script. Again, you will probably have to adjust these paths for your own circumstances, and you may even have to add a RewriteBase directive or something as well.

Now test your admin app. Everything should work correctly, but slowly.

[ Posted: 19:30] | [ Category: /computing/django] | Permalink | Comments: 2 ]

Watching the local wild/feral edible plants

Walking home from the bus stop today, I took notice of some wild and feral edible plants, and how far along they are in terms of availability. Some of them I had been familiar with, some of them I noticed for the first time, even though I’ve walked this route many times. Here’s what I found, in order of my path from the bus stop:

  1. A fairly large fig tree in a vacant lot. The lot is seprated from all the surrounding houses by fences or the street, so probably no one will object if we pick from this one. It has green figs on it; I expect they’ll be ready middle of next month, but I’d better check back weekly so I don’t miss them. The ants here get into the figs as soon as they’re ripe, and overripe figs are ruined fast.
  2. A really big fig tree, in another vacant lot. This lot is separated from the street by a partial fence, and the neighbours on either side park their cars in this lot. Odds are they’ll probably want these figs for themselves.
  3. Maypops or passionflowers, growing alongside the road at the powerline. We collected fruit from these last year, I guess in the late summer. The fruit is hollow, but has seeds covered in juicy pulp, unless you wait too long to harvest them, and they dry out. They didn’t have any flowers yet, much less fruit. This is a native species. Apparently the best use of the fruit is for making jelly.
  4. Wild black cherry, also native. This is all over the place. I just noticed that the fruit is suddenly ripe. This is good for casual snacking, and it’s probably good for jellies, too I’m kind of considering trying to make cherry wine, but I doubt I’ll have the time to get the equipment and so forth.

[ Posted: 18:22] | [ Category: /personal] | Permalink | Comments: 0 ]

 


Powered by PyBlosxom