mod_wsgi 用于非框架 Python Web 开发的 WSGI 脚本
我看到的大多数创建与 mod_wsgi 一起使用的 WSGI 文件的指南要么为 Django 要么为 Pylons 设置它。但是,我想创建 wsgi 文件而不为任何特定框架设置它。我该怎么做呢。以下是与 Django 一起使用的 wsgi 脚本中的代码:
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()
来自 google 的 mod_wsgi 集成 说我需要将以下代码添加到 WSGI 脚本中以覆盖 BASELINE 环境(是的,我正在使用基线和特定于应用程序的 virtualenv):
import site
site.addsitedir('/usr/local/pythonenv/PYLONS-1/lib/python2.5/site-packages')
如果我不将其用于任何用途,我的 WSGI 脚本将是什么样子具体框架?
编辑:这适用于 Apache 服务器
Most guides I saw for creating the WSGI file for use with mod_wsgi either sets it up for Django or Pylons. However, 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于 PEP 333 中的简单 wsgi 应用程序:
换句话说,您不需要根本不需要进行任何设置。您只需确保 mod_wsgi 可以在您的模块中找到符合 wsgi 的
application
对象。出于安全原因,您确实应该在 apache 发布的任何目录之外的另一个模块中定义您的应用程序,并将 wsgi 文件中的代码限制为导入该模块并将 wsgi 应用程序绑定到
application< 所需的最少代码。 /代码> 变量。
For the simple wsgi application in PEP 333:
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.