ImportError on Django site with mod_wsgi in Daemon mode

I am experimenting with running two wsgi applications configured on the same VirtualHost . One of myapp applications is the standard hello-world code specified here . It loads absolutely normal. Another uiapp app is the Django site. It does not work with ImportError .

I read in wsgi docs the python-path value is added to sys.path , so that is what I specified in my WSGIDaemonProcess for uiapp .

I cannot figure out if there is a problem with the Python code or with the Apache configuration.

This is my virtual host configuration:

  [ . . . ] # processGroups WSGIProcessGroup uiapp WSGIProcessGroup myapp # configurations for django sites WSGIScriptAlias /uiapp "/some/path/ui_dir/site_prod/wsgi.py" WSGIScriptAlias /myapp "/some/other/path/myapp.wsgi" # daemons WSGIDaemonProcess uiapp processes=2 threads=25 display-name=site_prod_wsgi python-path=/some/path/ui_dir WSGIDaemonProcess myapp processes=2 threads=25 display-name=helloworld_wsgi # doc root for /uiapp <Directory "/some/path/ui_dir/site_prod"> Order allow,deny Allow from all </Directory> # doc root for /myapp <Directory "/some/other/path"> Order allow,deny Allow from all </Directory> [ . . . ] 

I tried changing python-path from uiapp to /some/path/ui_dir/site_prod , but even with an error with the same error.

Error Log:

  mod_wsgi (pid=32652): Exception occurred processing WSGI script '/some/path/ui_dir/site_prod/wsgi.py'. Traceback (most recent call last): File "/home/usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 219, in __call__ self.load_middleware() File "/home/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 39, in load_middleware for middleware_path in settings.MIDDLEWARE_CLASSES: File "/home/usr/local/lib/python2.7/site-packages/django/utils/functional.py", line 184, in inner self._setup() File "/home/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup self._wrapped = Settings(settings_module) File "/home/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 95, in __init__ raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e)) ImportError: Could not import settings 'site_prod.settings' (Is it on sys.path?): No module named site_prod.settings 

This is the source for /some/path/ui_dir/site_prod/wsgi.py

 import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "site_prod.settings") from django.core.wsgi import get_wsgi_application application = get_wsgi_application() # Apply WSGI middleware here. # from helloworld.wsgi import HelloWorldApplication # application = HelloWorldApplication(application) 

Please help me figure out what I'm doing wrong.

+1
source share
4 answers

You cannot have two WSGIProcessGroup directives in such a line. Only the latter will be used. Thus, you are actually sending both applications to the same daemon process group instead of different ones. Having done this and getting them in the same process, you get into the setdefault () problem described in:

Move the WSGIProcessGroup directives inside the Directory blocks related to the corresponding WSGI script locations.

+4
source

if you are checking out a previous version of django docs version 1.3 instead of 1.4, the section How to use Django with Apache and mod_wsgi may help solve your problem. I encountered the same problem that you encountered when I configured virtual hosts. Therefore, instead of specifying python-path=/some/path/ui_dir in your virtual host configuration. You can do this in /some/path/ui_dir/site_prod/wsgi.py add the lines below to this file. Place these lines before the lines at the top of the file before importing and running django.

the code

 import sys path = '/some/path/ui_dir' if path not in sys.path: sys.path.append(path) 
+1
source

... and make sure you set DJANGO_SETTINGS_MODULE in wsgi.py

 os.environ['DJANGO_SETTINGS_MODULE'] = 'settings.could.be.somewhere.else' 
0
source

Try the following:

Host:

 <Virtualhost project.dev> DocumentRoot "/full/path/to/project/root/" WSGIScriptAlias / /full/path/to/wsgi/file/wsgi.py </Virtualhost> 

wsgi.py:

 sys.path = ['path/to/project/root'] + sys.path 
0
source

All Articles