Writing a simple python web app
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 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. 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 which seems to work pretty well for us.
> What do you recommend?
You have many options to pick from. I'd say, give Django anther
look :) Failing that, try web.py or CherryPy. 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.
More information about the PLUG