[Django]-Setting up Django with mod_python, Apache on SuSE with Alias

2👍

âś…

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.

1👍

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 🙂

0👍

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.

Leave a comment