Hi,

I'm sure this is a properly neophyte post, but I'm stumped and would
really appreciate some guidance. I am trying to serve a site under
apache2 using django. I have apache2 and mod_python installed (setup
below). I have followed the instructions at
http://docs.djangoproject.com/en/dev/howto/deployment/modpython/?from=olddocs
about configuring apache. My apache2.conf contains:

<Location "/WORD">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE WORD.settings
    PythonDebug On
    PythonPath "['/home/matthew/current/django','/home/matthew/current/
django/WORD'] + sys.path"
</Location>

When I navigate to localhost/WORD/publications (where my app is) I
see:

[START ERROR]
Mod_python error: "PythonHandler django.core.handlers.modpython"

Traceback (most recent call last):

  File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line
299, in HandlerDispatch
    result = object(req)

  File "/var/lib/python-support/python2.4/django/core/handlers/
modpython.py", line 163, in handler
    return ModPythonHandler()(req)

  File "/var/lib/python-support/python2.4/django/core/handlers/
modpython.py", line 125, in __call__
    if settings.ENABLE_PSYCO:

  File "/var/lib/python-support/python2.4/django/conf/__init__.py",
line 27, in __getattr__
    self._import_settings()

  File "/var/lib/python-support/python2.4/django/conf/__init__.py",
line 53, in _import_settings
    self._target = Settings(settings_module)

  File "/var/lib/python-support/python2.4/django/conf/__init__.py",
line 81, in __init__
    raise EnvironmentError, "Could not import settings '%s' (Is it on
sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE,
e)

EnvironmentError: Could not import settings 'WORD.settings' (Is it on
sys.path? Does it have syntax errors?): No module named WORD.settings
[END ERROR]

So apache2 is handing the request on to django via mod_python
appropriately, but django is failing to load the settings module. To
check that it has placed the module parent directory on the sys.path,
I added to the error message in /var/lib/python-support/python2.4/
django/conf/__init__.py like this:

[START CODE]
 raise EnvironmentError, "Could not import settings '%s' (Is it on
sys.path? Does it have syntax errors?): %s\n\nsys.path=%s" %
(self.SETTINGS_MODULE, e,sys.path)
[END CODE]

which produced:

[START ERROR]
EnvironmentError: Could not import settings 'WORD.settings' (Is it on
sys.path? Does it have syntax errors?): No module named WORD.settings

sys.path=['/home/matthew/current/django', '/home/matthew/current/
django/WORD', '/usr/lib/python24.zip', '/usr/lib/python2.4', '/usr/lib/
python2.4/plat-linux2', '/usr/lib/python2.4/lib-tk', '/usr/lib/
python2.4/lib-dynload', '/usr/local/lib/python2.4/site-packages', '/
usr/lib/python2.4/site-packages', '/usr/lib/python2.4/site-packages/
Numeric', '/usr/lib/python2.4/site-packages/cairo', '/var/lib/python-
support/python2.4', '/var/lib/python-support/python2.4/gtk-2.0', '/usr/
lib/site-python']
[END ERROR]

Which confirms the appropriate directories are visible. To check that
settings.py has no syntax errors, I ran the interpreter and executed
the following:

[START INTERPRETER]
$ python
Python 2.4.4 (#2, Apr 15 2008, 23:43:20)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path = ['/home/matthew/current/django'] + sys.path
>>> import WORD.settings
>>> WORD.settings.INSTALLED_APPS
('django.contrib.auth', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sites',
'django.contrib.admin', 'django.views.static', 'WORD.publications')
[END INTERPRETER]

so it loads ok with a normal import, but reading /var/lib/python-
support/python2.4/django.conf/__init__.py, the exception is raised in
__import__(), like this:

[START CODE]
try:
    mod = __import__(self.SETTINGS_MODULE, '', '', [''])
 except ImportError, e:
    raise EnvironmentError, "Could not import settings '%s' (Is it on
sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE,
e)
[END CODE]

so I also ran that command in the interpeter:

[START INTERPRETER]
>>> mod = __import__('WORD.settings', '', '', [''])
>>> mod
<module 'WORD.settings' from '/home/matthew/current/django/WORD/
settings.pyc'>
>>> WORD.settings.INSTALLED_APPS
('django.contrib.auth', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sites',
'django.contrib.admin', 'django.views.static', 'WORD.publications')
[END INTERPETER]

and it works fine in this instance. I'm sure that I'm missing
something blindingly obvious, but if someone could please point it out
to me I'd be really grateful.

I am using:
Debian Stable (Etch)
Python 2.4.4-2
Django 0.95.1-1etch2
Apache2  2.2.3-4+etch6
mod_python  3.2.10-4

Many thanks in advance,

Matthew

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to