如何将 Python 项目链接到 WSGI 文件?
我想将我的 Python 项目链接到 wsgi
文件。我正在使用 mod_wsgi
。
我希望我的 Python 项目位于 /var/www/myProject/start.py
中。
我已按如下方式配置 Apache:
<VirtualHost *:80>
ServerName www.example.me
ServerAlias example.me
ServerAdmin [email protected]
DocumentRoot /usr/local/www/documents
LogLevel warn
Alias /robots.txt /usr/local/www/documents/robots.txt
Alias /favicon.png /usr/local/www/documents/favicon.png
Alias /media/ /usr/local/www/documents/media/
<Directory /usr/local/www/documents>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias / /usr/local/www/wsgi-scripts/myApp.wsgi
<Directory /usr/local/www/wsgi-scripts>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
到目前为止,这是我在 myApp.wsgi
文件中的内容:
import web
urls = (
'/.*', 'hello',
)
class hello:
def GET(self):
return "Hello, world"
application = web.application(urls, globals()).wsgifunc()
为了链接位于 /var/ 中的项目,我需要做什么www/myProject/start.py
由 myApp.wsgi
调用?
I want to link my Python project to a wsgi
file. I am using mod_wsgi
.
I would like my Python project to be located in /var/www/myProject/start.py
.
I've configured Apache as follows:
<VirtualHost *:80>
ServerName www.example.me
ServerAlias example.me
ServerAdmin [email protected]
DocumentRoot /usr/local/www/documents
LogLevel warn
Alias /robots.txt /usr/local/www/documents/robots.txt
Alias /favicon.png /usr/local/www/documents/favicon.png
Alias /media/ /usr/local/www/documents/media/
<Directory /usr/local/www/documents>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias / /usr/local/www/wsgi-scripts/myApp.wsgi
<Directory /usr/local/www/wsgi-scripts>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
So far this is what I have in myApp.wsgi
file:
import web
urls = (
'/.*', 'hello',
)
class hello:
def GET(self):
return "Hello, world"
application = web.application(urls, globals()).wsgifunc()
What do I have to do in order to link my project which is located in /var/www/myProject/start.py
to be called by myApp.wsgi
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 WSGIScriptAlias 的最后一个参数替换为“/var/www/myProject/start.py”。
将目录指令中的引用更改为“/var/www/myProject”。换句话说,只需首先将配置设置为指向正确的位置即可。
Replace final argument to WSGIScriptAlias with '/var/www/myProject/start.py'.
Change reference in Directory directive to '/var/www/myProject'. In other words, just set the configuration to point to the correct location in the first place.
看来您的 start.py 位于不同的目录中,您想从 wsgi.py 调用它。
更好的方法是将 wsgi 文件放在与 start.py 相同的文件夹中,然后从那里导入并加载应用程序..类似于:
It seems that you have start.py in a different directory which you want to invoke from wsgi.py.
A better way will be to have wsgi file in the same folder as the start.py, and just import and load the application from there.. something like: