Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

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.

share|improve this answer
add comment

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 :)

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["        <li><a href=\"http://area51.stackexchange.com\" title=\"proposing new sites in the Stack Exchange network\">Area 51</a></li>\r\n                        <li><a href=\"http://careers.stackoverflow.com\">Stack Overflow Careers</a></li>\r\n                    \r\n                </ol>\r\n            </td>\r\n    </tr>\r\n</table>\r\n                </div>\r\n            </div>\r\n\r\n            <div id=\"copyright\">\r\n                site design / logo &#169; 2014 stack exchange inc; user contributions licensed under <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc by-sa 3.0</a> \r\n                with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2014.7.11.1706\r\n            </div>\r\n            \r\n        </div>\r\n    </div>\r\n    <noscript>\r\n        <div id=\"noscript-warning\">Stack Overflow works best with JavaScript enabled<img src=\"http://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif\" alt=\"\" class=\"dno\"></div>\r\n    </nos"], "copyright__copyright__copyright": ["ease, 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.\n\nSpawning/FastCGI is even better in the way you don't even bother with Apache at all.\n\nshare|improve this answer\nadd comment\n\nYour Answer\n\n\u00a0\ndiscard\n\nBy posting your answer, you agree to the privacy policy and terms of service.\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}