开发者

mod_wsgi WSGI script for non-frameworked Python web development

Most guides I saw for creating the WSGI file for use with mod_wsgi either sets it up for Django or Pylons. Ho开发者_运维百科wever, I would like to create the wsgi file without setting it up for any particular framework. How do I do this. The following is a code from the wsgi script for use with Django:

import os, sys
sys.path.append('/home/user/dev')
sys.path.append('/home/user/dev/site1')
os.environ['DJANGO_SETTINGS_MODULE'] = 'site1.settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

The mod_wsgi integration from google said that I need to add the following code to the WSGI script to overlay the BASELINE environment (yep, I am using a baseline and application-specific virtualenv):

import site
site.addsitedir('/usr/local/pythonenv/PYLONS-1/lib/python2.5/site-packages')

How will my WSGI script look like if I am not using it for any particular framework?

EDIT: This is for use with Apache server


For the simple wsgi application in PEP 333:

def simple_app(environ, start_response):
    status = '200 OK'
    response_headers = [('Content-type', 'text/plain')]
    start_response(status, response_headers)
    return ['Hello world!\n']

application = simple_app

In other words, you don't have to do any setup at all. You just have to make sure that mod_wsgi can find an application object that conforms to wsgi in your module.

For security reasons, you really ought to define your application in another module outside any directories published by apache, and limit the code in your wsgi file to the minimum required to import that module and bind the wsgi application within to the application variable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜