How to change pythonpath for WSGI application in alwaysdata.net

I created a small Python web application using Flask, and I wanted to put it in the alwaysdata.net file. I already installed mod_wsgi in my subdomain, but when I try to import the main module of my application, it fails because it cannot be found. All files are located in the / www folder.

Should I post files elsewhere? I tried to include the current working directory in my .wsgi file, but it still does not work.

For reference, my .wsgi looks like this:

import os import sys sys.path.append(os.getcwd()) from ngl import app as application 

My application is called ngl.py and it is in the same folder as the .wsgi file.

Thanks!

+4
source share
1 answer

The current working directory in mod_wsgi will not be where the WSGI script is located, so you should not use os.getcwd (). Cm:

http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Application_Working_Directory

To do what you want, use:

 sys.path.append(os.path.dirname(__file__)) 

This computes the directory that the WSGI script file is in, obtaining the component of the directory path of the WSGI script file name written in the __file__ variable.

+12
source

All Articles