Django + mod_wsgi + apache: ImportError at / No module named djproj.urls Django + mod_wsgi + apache: ImportError at / No module named djproj.urls django django

Django + mod_wsgi + apache: ImportError at / No module named djproj.urls


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 osimport syssys.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 WSGIHandlerapplication = WSGIHandler()


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.


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