2

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.

4 Answers 4

7

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
Updated my answer with full urlconf setup
3

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.

3 Comments

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.
i added from myproject.orgDisplay import views to my urls.py file and still no luck.
My mistake. I copied your code directly and forgot to make the changes. Fixed now.
0

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"))

Comments

0

Provided your WSGI file is in your project directory, a slightly more flexible way is this:

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

This will enable you to change your project location later without having to modify your WSGI file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.