Not giving you an answer yet, but few comments and questions below.
2008/11/4 Max Ischenko <[EMAIL PROTECTED]>:
>
> Hello,
>
> I'm trying to run Django/Pylons app under mod_wsgi and get this error:
Can you explain more how Django and Pylons are being run as a
composite application and why you need to do this?
If you are merely trying to have one appear at a sub URL context of
the other, but there is no interaction between the two, you would be
better off mounting them as separate WSGI applications at
Apache/mod_wsgi level rather than trying to use Pylons feature to do
the same. Benefit of this is that they can run in separate sub
interpreters or even daemon processes and thus not interfere with each
other.
Only reasons can think to using Pylons to composite them together is
if one is providing session management for the other to get SSO, or if
WSGI middleware being used to modify the response of the other.
> mod_wsgi (pid=9231): Exception occurred processing WSGI script '/var/
> www/site-djangoapp/django.wsgi'.
> Traceback (most recent call last):
> File "/var/www/site-djangoapp/py/lib/python2.5/site-packages/django/
> core/handlers/wsgi.py", line 239, in __call__
> response = self.get_response(request)
> File "/var/www/site-djangoapp/py/lib/python2.5/site-packages/django/
> core/handlers/base.py", line 72, in get_response
> urlconf = getattr(request, "urlconf", settings.ROOT_URLCONF)
> File "/var/www/site-djangoapp/py/lib/python2.5/site-packages/django/
> conf/__init__.py", line 32, in __getattr__
> return getattr(self._target, name)
> File "/var/www/site-djangoapp/py/lib/python2.5/site-packages/django/
> conf/__init__.py", line 147, in __getattr__
> return getattr(self.default_settings, name)
> AttributeError: 'module' object has no attribute 'ROOT_URLCONF'
>
> I'm using virtualenv python. Here is relevant Apache config lines;
>
> WSGIPythonHome /var/www/site-djangoapp/py
Was this virtual environment created with --no-site-packages or is it
chained off main Python installation and therefore inheriting
packages/modules from main Python installation as well.
If chained off main Python installation, are there versions of
packages/modules in main Python installation site-packages directory
which are also separately installed in the virtual environment.
> <VirtualHost *>
> WSGIProcessGroup max
> WSGIDaemonProcess max user=max group=www-data threads=2 maximum-
> requests=1000
> WSGIScriptAlias / /var/www/site-djangoapp/django.wsgi
> </VirtualHost>
>
> My django app is at doudj package and my pylons app is at doupy
> package.
>
> Executing module content from the command line works:
> $ python django.wsgi
> $ type python
> python is hashed (/var/www/site-djangoapp/py/bin/python)
>
> $ cat django.wsgi
> import sys
> import os
> import os.path
>
> heredir = os.path.dirname(__file__)
> sys.path.insert(0, heredir)
This suggest that you have the .wsgi file in parent directory to both
projects. This wouldn't generally be recommended, as for
Apache/mod_wsgi to be able to use that file, you would have needed a
Directory directive for directory saying Apache can uses files in that
directory. That is, would have 'Allow from all'. Since source code now
subordinate to that directory, if you were to stuff up Apache
configuration and expose that directory, someone could possibly get
your source code. Thus better for .wsgi file to be in directory of its
own with nothing else important in that directory or a sub directory
of it and only that directory exposed through Apache. That way less
risk of exposing source code.
> os.environ['DJANGO_SETTINGS_MODULE'] = 'doudj.settings'
>
> import doudj.settings
> assert doudj.settings.ROOT_URLCONF, doudj.settings
> from django.core.handlers.wsgi import WSGIHandler
>
> django_app = WSGIHandler()
>
> from paste.deploy import loadapp
> doupy_app = loadapp('config:config.ini',
> relative_to=os.path.join(heredir, 'doupy'))
>
> application = django_app
This is what I don't understand. The entry point is the Django
application. How does the Pylons application get mapped into URL
namespace or invoked?
> And here is where the mystery starts.
>
> If I comment out loadapp() call to init my Pylons app it magically
> starts working. If I re-enable it I get that AttributeError in
> _django_ code. And I have no idea why I don't observe the error from
> the command line.
>
> I need your help guys.
What I would suggest to start with is add debugging which dumps out
what sys.path is at various points in script.
import sys
print >> sys.stderr, "#1 %s" % sys.path
This will go to Apache error log.
See in what way Pylons initialisation may play with what is in
sys.path, ie., what it adds etc.
Ultimately this shouldn't matter as you are explicitly importing
Django settings module before that though.
Also add you assertion checks:
assert doudj.settings.ROOT_URLCONF, doudj.settings
after Pylons initialisation. Do they fail at that point?
If they do, add code before it which dumps out __file__ from doudj,
doudj.settings. Also dump out dir(doudj), dir(doudj.settings).
That is just validate a bit is in that module at various steps.
If you are mentioning Django in Pylons configuration file so as to
merge it into URL namespace, also post what the configuration file has
in it.
Graham
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"modwsgi" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/modwsgi?hl=en
-~----------~----~----~----~------~----~------~--~---