Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modify pythonpath for a WSGI application in alwaysdata.net

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

Should I place my files somewhere else? I tried including the current working directory in my .wsgi file but it still doesn't 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's in the same folder as the .wsgi file.

Thanks!

like image 874
nicolasmgl Avatar asked Dec 17 '22 12:12

nicolasmgl


1 Answers

The current working directory under mod_wsgi will not be where the WSGI script is located, so you shouldn't be using os.getcwd(). See:

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 is calculating the directory the WSGI script file is in by getting the directory path component of the name of the WSGI script file as recorded in __file__ variable.

like image 193
Graham Dumpleton Avatar answered Jan 05 '23 18:01

Graham Dumpleton