[Fixed]-Django + mod_wsgi + apache: ImportError at / No module named djproj.urls

25👍

Either change all your module/package entries and imports to exclude the project name, or put /srv/www/site.com in sys.path as well.

36👍

I second Ignacio Vazquez-Abrams’s answer. You must add the path to your project directory as well as the path to its parent directory to sys.path. Here is an example of the WSGI script file I use. I keep the file inside the project directory.

import os
import sys

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../")))
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../")))

os.environ["DJANGO_SETTINGS_MODULE"] = "PROJECT_NAME.settings"

from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()
👤ayaz

11👍

Seconding ayaz’ answer. It’s important that the paths you’re specifying be at the beginning of the search path, which means you need to use insert..

Here’s mine. When I was doing an ‘append’ I was getting intermittent issues. This made it rock solid. Hope this helps.

sys.path.insert(0, '/srv/www/Appname')
sys.path.insert(1, '/srv/www')

5👍

try following this tutorial – http://singlas.in/5-step-tutorial-for-using-django-with-apache-and-mod_wsgi/

Make sure to add both Django directory and Django Project Directory to system path. your wsgi.py should look like

import os,sys

#comments
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_project.settings")
sys.path.append('/path/to/your/django/directory/django_project')
sys.path.append('/path/to/your/django/directory')

#comments
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

2👍

What corrected this error for me —

Changing settings.py from:

ROOT_URLCONF = ‘urls’

To this:

ROOT_URLCONF = ‘myproject.urls’

👤Ken

1👍

where you have djproj.urls maybe try just urls

👤darren

Leave a comment