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

ⅰ亾dé卋堺 提交于 2019-11-28 08:27:48

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.

ayaz

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

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

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

What corrected this error for me --

Changing settings.py from:

ROOT_URLCONF = 'urls'

To this:

ROOT_URLCONF = 'myproject.urls'

where you have djproj.urls maybe try just urls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!