tags:

views:

80

answers:

2

I'm trying to deploy my Django app into production on a shared server.

It seems I'm having problems with the Python path because I'm getting the error from the server: No module named products.models

However, when I go to the root of the app and run the shell the modules load fine.

'>>> from products.models import Answer
'>>> import sys
'>>> sys.path
['/home/SecretUserAcct/django-projects/review_app', ...]

The path above does point to the root of the Django app.

I'm guessing this is an issue with the Python path, but I'm not sure what is going wrong.

Here is the fcgi file: $ cat ~/public_html/django.fcgi

#!/usr/local/bin/python2.6 
import sys
import os

# Insert PYTHONPATH values here, including the path to your application
#sys.path.insert(0, '<path_to_your_app_directory>')
sys.path.insert(0, '/home/SecretUserAcct/django-projects/')
# Provide the location of your application's settings file.
os.environ['DJANGO_SETTINGS_MODULE'] = 'review_app.settings'

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method = "threaded", daemonize = "false", maxchildren=3, minspare=0, maxspare=1)

What understanding am I missing here?

A: 

I'm somewhat confused -- if what you have in the path in the working case is:

'/home/SecretUserAcct/django-projects/review_app'

i.e., including the app, why are you instead, in the second non-working case, inserting

'/home/SecretUserAcct/django-projects/'

i.e., WITHOUT the app? Surely you'll need different forms of import depending on what you chose to put on your sys.path, no?

Alex Martelli
You make a valid point, the reason it's set up like that is due to these instruction from my shared host:The <path_to_your_app> is the location of your Django application folder from #1. This is NOT the location of the application folder itself, but rather the folder that CONTAINS the application folder. For example, if my application folder is named "mysite" and I have placed it in a folder named "python", then I want to point to /python, NOT to /mysite. The reason has to do with the manner in which Python loads modules.
BryanWheelock
@Bryan, then you'll have to change your import statements accordingly, to explicitly use your app's name.
Alex Martelli
A: 

The Django dev server and manage.py shell put the current directory (the directory you ran manage.py from) on your python path for you. When running in production mode, you'll need to adjust your path accordingly if you have code that relies on that feature.

Brian Neal