Reputation: 12574
We are trying to get out wsgi application working on mod_wsgi. We have run it before using wsgiref.simple_server
, as a debugging environment. Now, we want to move it over to using Apache httpd to integrate with loading static files under the same port, and to provide an environment more suitable for production.
The httpd.conf file we have set up looks like this:
<VirtualHost *:80>
DocumentRoot /var/www/
ErrorLog /var/www/log/error_log
LogLevel debug
WSGIScriptAlias /app /var/www/python/resource/rest.py
<Directory /var/www/python/>
Order allow,deny
Allow from all
</Directory>
<Directory />
Order allow,deny
Allow from all
RewriteEngine On
# Some rewrites go here
</Directory>
</VirtualHost>
With this setup, we can access the main application file, rest.py (under http://myhost/app
), but any imports to modules (like from module1 import function
where module1 is under the same directory as rest.py) are failing with an ImportError
.
I suspect this has to do with having to set some sort of environment variable, but I have added /var/www/python
to sys.path
on the main application method and it doesn't work. Any help or pointers with this would be really appreciated.
Thanks!
Upvotes: 3
Views: 2268
Reputation: 557
Is rest.py under /var/www/python or /var/www/python/resource? Adding this directory to sys.path should work as far as I know. Preferable to using a string constant would be the following:
sys.path.append(os.path.dirname(__file__))
This should work even if you decide to deploy to a different location in the future.
Upvotes: 6