I’m having major problems getting Django working with my Apache configuration. I did not create the server, so I don’t have too much leeway as to how the server works. Essentially there are three virtual hosts:
board.site.org, students.site.org and insider.site.org
The insider.site.org is the main one I’m concerned with. I’m in charge of a small site underneath it (ideally at insider.site.org/tech). I decided to put my files separate from the original directory, as not to chance messing up something in there (since a non-python site is already in place). Anyway, my virtual hosts are defined in separate files in /etc/apache2/vhosts.d/
Here’s what the insider.site.org’s config looks like
insider.conf
LoadModule python_module /usr/lib64/apache2/mod_python.so <VirtualHost 10.10.1.1:80> ServerName insider.site.org DocumentRoot /media/nss/VWEB/docs <Directory /media/nss/VWEB/docs> Options Indexes Multiviews AllowOverride None Order Allow,Deny #Allow from 10.11.0.78 Allow from all </Directory> Alias /tech /srv/www/Tech <Directory /srv/www/Tech> SetHandler python-program PythonPath '['/srv/www/Tech'] + sys.path' PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE Tech.settings PythonDebug On </Directory> Alias /media /srv/www/Media <Directory /srv/www/Media> SetHandler None </Directory> </VirtualHost>
- Note that when saying site.org, I’m referring to my site, not the actually ‘site.org’ web address.
Now, it seems like that should be right to me, but for some reason, accessing http://insider.site.org/tech/ gives me this error:
Mod_python error: ‘PythonHandler mod_python.publisher’
Traceback (most recent call last):
File ‘/usr/lib64/python2.4/site-packages/mod_python/apache.py’, line 299, in HandlerDispatch result = object(req)
File ‘/usr/lib64/python2.4/site-packages/mod_python/publisher.py’, line 98, in handler path=[path])
File ‘/usr/lib64/python2.4/site-packages/mod_python/apache.py’, line 454, in import_module f, p, d = imp.find_module(parts[i], path)
ImportError: No module named index
Whereas http://insider.site.org/tech (no trailing forward slash) results in a 403 error. I do have Django in this directory, but it simply isn’t getting executed (I have _ init _.py in all my directories under the tech folder, and this is a copy from my own personal computer (which ran off of the django test server)) so I don’t think that’s the problem. This is simply not working 🙁
Any help is appreciated, thanks.
For your first problem, are you sure you have Django in the PythonPath you have specified? On my server, the list in my PythonPath includes the directory containing the top-level django directory, which itself contains the bin, contrib, admin, core, etc. directories, in addition to __init__.py. (Also make sure your Apache user has read and execute permissions for these files and directories, although I’m sure this is obvious.) This is my setup:
Note that I’m using Location instead of Directory here, so your mileage may vary.
For your second problem, that sounds like a problem for mod_rewrite. See here. You can let the server append the slash you need automatically by defining a rewrite rule:
Hope that helps.