Django + mod_wsgi on virtualenv not working

I just finished setting up the django application on virtualenv, the deployment went smoothly using the script fabric, but now .wsgi does not work, I tried all the options on the Internet, but no luck. My .wsgi file:

import os import sys import django.core.handlers.wsgi # put the Django project on sys.path root_path = os.path.abspath(os.path.dirname(__file__) + '../') sys.path.insert(0, os.path.join(root_path, 'kcdf')) sys.path.insert(0, root_path) os.environ['DJANGO_SETTINGS_MODULE'] = 'kcdf.settings' application = django.core.handlers.wsgi.WSGIHandler() 

I keep getting the same error:

 [Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] mod_wsgi (pid=16938): Exception occurred processing WSGI script '/home/kcdfweb/webapps/kcdf.web/releases/current/kcdf/apache/kcdf.wsgi'. [Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] Traceback (most recent call last): [Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/wsgi.py", line 230, in __call__ [Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] self.load_middleware() [Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 33, in load_middleware [Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] for middleware_path in settings.MIDDLEWARE_CLASSES: [Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] File "/usr/local/lib/python2.6/dist-packages/django/utils/functional.py", line 269, in __getattr__ [Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] self._setup() [Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] File "/usr/local/lib/python2.6/dist-packages/django/conf/__init__.py", line 40, in _setup [Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] self._wrapped = Settings(settings_module) [Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] File "/usr/local/lib/python2.6/dist-packages/django/conf/__init__.py", line 75, in __init__ [Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] raise ImportError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e) [Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] ImportError: Could not import settings 'kcdf.settings' (Is it on sys.path? Does it have syntax errors?): No module named kcdf.settings 

my virtual environment is enabled / home / user / webapps / kcdfweb my application: /home/user/webapps/kcdf.web/releases/current/project_name my wsgi file home / user / webapps / kcdf.web / releases / current / project_name / apache / project_name.wsgi

+7
django virtualenv mod-wsgi
source share
4 answers

I would recommend looking at the docs for using Virtualenv with mod_wsgi. They offer several alternative connection approaches in your virtualenv that might work better for you.

+7
source share

You need to add a directory that is twice the size of your wsgi file, so instead:

 root_path = os.path.abspath(os.path.dirname(__file__) + '../') 

you should have

 root_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../', '../')) 

... since your wsgi file is in a directory called apache in the project folder.

+1
source share

If you are using virtualenv, you need to activate it in the WSGI script in order to set the paths correctly.

 root_path = os.path.abspath(os.path.dirname(__file__) + '../') activate_this = os.path.join(root_path, "bin/activate_this.py") execfile(activate_this, dict(__file__=activate_this)) 
0
source share

Do you have a __init__.py file in your kcdf directory? Without this, your settings file cannot be imported.

In addition, you must call site.addsitedir () in the virtual sitesite directory if you want to import material from virtualenv. See the mod_wsgi docs for more details. Although, if he can’t even import your settings, I don’t think this is your current problem.

0
source share

All Articles