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()
- Soft deleting objects in django
- Django reset_password_confirm TemplateSyntaxError problem
- Django/python: 'function' object has no attribute 'as_view'
- Graphene Django – Mutation with one to many relation foreign key
- Django convert model instance to dict
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')
- Django url patterns with 2 parameters
- Why are migrations files often excluded from code formatting?
- How to customise django inline admin form's delete function
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()
- Django template counter in nested loops
- Custom user model in django
- How to get coverage data from a django app when running in gunicorn
- Prettier vscode extension not support Django template tags {% tag %}
- Django-allauth SITE_ID error
2👍
What corrected this error for me —
Changing settings.py from:
ROOT_URLCONF = ‘urls’
To this:
ROOT_URLCONF = ‘myproject.urls’
- Django newbie deployment question – ImportError: Could not import settings 'settings'
- Is there any way to use GUIDs in django?