Monday, January 31, 2011

Simple wsgi apps without using a framework.

Using apache and mod_wsgi, serve a dirt simple app (useful for mocking services that havent been created yet by other programmers).

After installing mod_wsgi (sudo apt-get install libapache2-mod-wsgi)

Apache conf:
WSGIScriptAlias /webdir/ /filesys/dir/
With this you can call wsgi scripts in 'webdir' as localhost/webdir/test.py

python WSGI code for the file /filesys/dir/test.py:

def application(environ, start_response):
response_body = '{"fake-json":"temp-output"}'
status = '200 OK'
response_headers = [('Content-Type', 'application/json'),
('Content-Length', str(len(response_body)))]
start_response(status, response_headers)

return [response_body]

Done. No stupid framework needed for stupid simple apps.

No comments:

Post a Comment