views:

653

answers:

3

I had a small proof of concept set up on a development server on a local machine. I'm now trying to move it over to django on a production server, which I'm using webfaction for. However, now that I'm switched over to apache from the built in django server I get the following:

ViewDoesNotExist: Could not import orgDisplay.views. Error was: No module named orgDisplay.views

But when check my orgDisplay apps folder there is a view.py in it. What am I doing wrong? I've tried adding the following to my settings.py by suggestion of the django IRC room.

import sys
sys.path.append(r"/home/user/webapps/django_project/myproject/orgDisplay")

which is the path to my app.

any ideas on how to even begin to trouble shoot this?

Thanks in advance.

+3  A: 

I think you're appending the wrong directory to sys.path. I think Python is looking in the .../myproject/orgDisplay folder for the orgDisplay package. Try removing the orgDisplay from your string, like this:

import sys
sys.path.append(r"/home/user/webapps/django_project/myproject")

The other option would be to simply add myproject (or whatever your project is actually called) in the import statement.

# instead of "from orgDisplay import views"
from myproject.orgDisplay import views

Also, make sure to restart Apache after every edit.

bluejeansummer
I don't see the difference between your append statement and mine.Also, where would I add the import statement. In my urls.py file? That is where I'm calling this from.
NoahClark
i added from myproject.orgDisplay import views to my urls.py file and still no luck.
NoahClark
My mistake. I copied your code directly and forgot to make the changes. Fixed now.
bluejeansummer
+3  A: 

I assume you're using mod_wsgi (which is recommended by Django authors), not mod_python. This is the way you should use your sys.path:

django.wsgi:

import os, sys
sys.path.append(r"/home/user/webapps/django_project/myproject/")
os.environ["DJANGO_SETTINGS_MODULE"] = "settings"

sys.stdout = sys.stderr # Prevent crashes upon print

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

urls.py:

from django.conf.urls.defaults import *
urlpatterns = (
   ("", include("orgDisplay.urls")),
   # ...
)

orgDisplay/urls.py:

import views

urlpatterns = ( 
    (r'^some_view/$', views.some_view), # It is actually orgDisplay.views.some_view
    # many more records ...
)

It is a bad idea to add project dir itself to path since you're be getting name conflicts between multiple projects.

Alex Lebedev
I believe if I added import orgDisplay.views that would probably fix it. So do I add that to my urls.py file? It seems odd I'd have to go mucking around in my settings like that.
NoahClark
Updated my answer with full urlconf setup
Alex Lebedev
A: 

looking at manage.py, it does it like so:

import sys

from os.path import abspath, dirname, join
from django.core.management import setup_environ


# setup the environment before we start accessing things in the settings.
setup_environ(settings_mod)

sys.path.insert(0, join(PINAX_ROOT, "apps"))
sys.path.insert(0, join(PROJECT_ROOT, "apps"))