Writing a simple python web app

Gabriel Gunderson gabe at gundy.org
Sat Sep 11 16:57:13 MDT 2010


On Sat, Sep 11, 2010 at 3:40 PM, Dave Smith <dave at thesmithfam.org> wrote:
> I'm creating a very simple web application, and I want to use python. My first guess was that mod_python would provide the easiest entry point. Boy, was I wrong. All the mod_python tutorials spend 80% of their time extolling the virtues of mod_python over CGI, but they are quite lean on specific examples. It's quite disappointing. A natural progression then leads me to mod_wsgi, and since that has equally poor documentation, to Django. However, Django is overkill for my app (I don't even have a database).

I thought the PEP[0] on WSGI was pretty helpful (it's obviously not
specific to Apache's mod_wsgi).

Since you mention documentation, Django's docs are second to none.
You must already know Django can be run without a database; I wont go
there.  I maintain that it's worth giving it another look for all the
other functionality that it provides: URL routing, forms with
validation (they do not require the ORM and can also be use
independent of HTTP forms), elegant templating, session management
(can be file based), CSRF and XSS protection, etc. Generally speaking,
Django is loosely coupled[1].  You can pick and choose as you like.


> What I want is something as simple as PHP. Just let me drop my files in and start editing. I don't want to have to add some configuration directive to httpd.conf for every new file or directory in my web app. I really want to use python for this. I'd be open to alternatives, like PHP, but PHP's YAML support is junk (tried several libraries already, and they all fail to correctly parse the YAML that some other python code produces).

If you're going to use Python, then you're likely going to have to
warm up to the idea of WSGI.  It seems to be the way things are going.
That makes the httpd.conf issue a bit of a moot point (as you'll end
up dealing with frameworks that use it *or* if you write an app to
talk directly to a WSGI server).  Also, you're not required to change
your config for every new URL, you just delegate everything to your
Python app and take it from there.

I don't have a ton to say about the YAML issue.  We like YAML and use
it with our Python/Django apps.  That functionality is provided by
PyYAML[2] which seems to work pretty well for us.


> What do you recommend?

You have many[3] options[4] to pick from.  I'd say, give Django anther
look :)  Failing that, try web.py[5] or CherryPy[6]. Both are very
pythonic and can be used to serve the page directly (avoiding that
whole WSGI thing).


Best of luck.  Let us know what you end up choosing and how it works out.

Gabe

0) http://www.python.org/dev/peps/pep-0333/
1) http://docs.djangoproject.com/en/dev/misc/design-philosophies/#loose-coupling
2) http://www.pyyaml.org/wiki/PyYAMLDocumentation
3) http://wiki.python.org/moin/WebFrameworks
4) http://en.wikipedia.org/wiki/Comparison_of_web_application_frameworks#Python
5) http://webpy.org/
6) http://cherrypy.org/


More information about the PLUG mailing list