Could not import/No module named Django Error with Apache Could not import/No module named Django Error with Apache apache apache

Could not import/No module named Django Error with Apache


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, syssys.path.append(r"/home/user/webapps/django_project/myproject/")os.environ["DJANGO_SETTINGS_MODULE"] = "settings"sys.stdout = sys.stderr # Prevent crashes upon printimport django.core.handlers.wsgiapplication = django.core.handlers.wsgi.WSGIHandler()

urls.py:

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

orgDisplay/urls.py:

import viewsurlpatterns = (     (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.


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 syssys.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.


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

import sysfrom os.path import abspath, dirname, joinfrom 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"))