这是一个想法(需要充实,可能行不通):
这是我要开始的:
from mod_python import apache
from wsgiref.handlers import BaseHandler
class MyWSGIHandler(BaseHandler):
def __init__(self, apachereq):
BaseHandler.__init__(self)
self.apachereq = apachereq
def _write(self, data):
self.apachereq.write(data)
# override the other required methods of BaseHandler, see
# http://docs.python.org/library/wsgiref.html#wsgiref.handlers.BaseHandler
wsgi_app = create_your_wsgi_app()
def handler(req):
wsgi_handler = MyWSGIHandler(req)
wsgi_handler.run(wsgi_app)
return apache.OK
IDEA 2(相当老套):
您还可以在处理程序代码中使用werkzeug wsgi 测试模块将请求传递给 WSGI 应用程序,获取 werkzeug 响应,然后将该响应写入 apache。
就像是:
from mod_python import apache
from werkzeug.test import Client
from werkzeug.wrappers import BaseResponse
wsgi_app = create_your_wsgi_app()
def handler(req):
c = Client(wsgi_app, BaseResponse)
resp = c.get(somehow_get_the_url_from(req)) # or c.post if it's a POST request
req.write(resp.data) # ... and find a way to write the headers as well
return apache.OK