I have a project in Django 1.1.4 and I am trying to set up this project on production with mod_wsgi but I am getting some errors :
My wsgi file code :
import os
import sys
import site
# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('path_to_\site-packages')
# Add the app's directory to the PYTHONPATH
sys.path.append('path_to_dir')
sys.path.append('path_to_dir')
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
I have tried to debug the error like when I print something in my settings It doesn't get print so I guess my settings is not being called.
My wsgi and settings file are in the same level and I have used two ways to mention settings in my wsgi file like os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
and os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'
but both fails. .
error - log :
File "C:\\Python27\\lib\\site-packages\\django\\core\\handlers\\wsgi.py", line 230, in __call__
self.load_middleware()
File "C:\\Python27\\lib\\site-packages\\django\\core\\handlers\\base.py", line 33, in load_middleware
for middleware_path in settings.MIDDLEWARE_CLASSES:
File "C:\\Python27\\lib\\site-packages\\django\\utils\\functional.py", line 272, in __getattr__
self._setup()
File "C:\\Python27\\lib\\site-packages\\django\\conf\\__init__.py", line 40, in _setup
self._wrapped = Settings(settings_module)
File "C:\\Python27\\lib\\site-packages\\django\\conf\\__init__.py", line 75, in __init__
raise ImportError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'cbc_website.settings' (Is it on sys.path? Does it have syntax errors?): No module named cbc_website.settings
Python is interpreting your '\' in the path definitions as an escape character. https://docs.python.org/2/reference/lexical_analysis.html#string-literals
Use r'path'
when specifying a literal path with backslashes. So instead of:
sys.path.append('C:\\\something')
You specify:
sys.path.append(r'C:\\\something')
in your wsgi.py
file.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments