views:

1055

answers:

3

Hello guys, 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.

+1  A: 

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:

<Location "/myapp">
   SetHandler python-program
   PythonHandler django.core.handlers.modpython
   SetEnv DJANGO_SETTINGS_MODULE LogFileAnalyzer.settings
   PythonDebug on
   PythonPath "['/srv/www/dir_containing_django_dir', '/srv/www/myapp_dir'] + sys.path"
</Location>

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:

RewriteEngine  on
RewriteBase    /~quux/
RewriteRule    ^foo$  foo/  [R]

Hope that helps.

Jeff
+1  A: 

Alias /tech /srv/www/Tech should be removed, and <Directory /srv/www/Tech> should be converted to a location.

Remember, you're not trying to get Apache to serve up your Python-files, you're telling it to start a certain Python process when it hits a specific location.

Also, may I suggest that you use sub-domains instead of having your Django-app in a "folder" on your primary domain. It tends to simplify things in my opinion.

Also for your consideration is mod_wsgi. I recently started using it for my Django apps, and they've taken a quantum leap forward in performance and stability :)

mikl
A: 

Possibly not as helpful for mod_python problem, but really, mod_python is worst way to deploy Django (actually worst way to deploy any kind of Python at all).

Please, consider using mod_wsgi at least, it's better for performance and a number of other reasons. Also, you'll have excellent support from devs of that mod at #django on freenode.

Spawning/FastCGI is even better in the way you don't even bother with Apache at all.

temoto
Sorry I did not respond. I actually /did/ get this working. If I recall correctly (it has been four months) it was exactly what you said. I needed to change it to a location.Also, I will take a look at mod_wsgi, since I got two recommendations for it almost instantly. Lastly, as far as the sub folder is concerned, my supervisor (non-developer, of course) didn't want to create a sub domain for me, and he chose to have the /tech/ sub folder. All that really does for me is changes my urls.py file, so I don't mind so much.Thanks for all the help, really appreciate it!
Paul Zaczkowski