How to link a Python project to a WSGI file?
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 example@gmail.com
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 开发者_JS百科/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
?
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.
It seems that you have start.py in a different directory which you want to invoke from wsgi.py.
- In this case, you need to somehow tell wsgi.py to be able to import a module from a different folder. This thread has some details on that.
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:
import start
start.load_application()
精彩评论