Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

This is my personal dev server that I recently started setting up. Although Python works as a cgi and standalone test scripts in Python run fine, Django does not seem to be working. All I see is the directory listing in browser of django files. Any help would be appreciated.

My Virtual Host:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    #DocumentRoot /var/www
    DocumentRoot /home/aj/public_html

    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    #<Directory /var/www/>
    <Directory /home/aj/public_html/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all  
            AddHandler mod_python .py
            #PythonHandler mod_python.publisher
            PythonHandler mod_python.cgihandler
            PythonDebug On
    </Directory>
    <Location "/home/aj/public_html/old/testing/">
            SetHandler python-program
            PythonHandler django.core.handlers.modpython
            SetEnv DJANGO_SETTINGS_MODULE testing.settings
            PythonOption django.root /testing
            PythonDebug On
    </Location>


    #ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    #<Directory /usr/lib/cgi-bin/>
    #ScriptAlias /cgi-bin/ /var/www/cgi-bin/
    #<Directory /var/www/cgi-bin/>
    ScriptAlias /bin/ /home/aj/public_html/
    <Directory /home/aj/public_html/>
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
    </Directory>

    ErrorLog /var/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel debug

    CustomLog /var/log/apache2/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
            Options Indexes MultiViews FollowSymLinks
            AllowOverride None
            Order deny,allow
            Deny from all
            Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
</VirtualHost>

I installed Django using

sudo apt-get install python-django
share|improve this question
1  
mod_python is depreciated in favour of mod_wsgi, consider switching to that. –  topdog Aug 20 '10 at 6:22
    
Really? is mod_wsgi favored more by just Djangonauts or is it a recommendation from Django framework team? –  sabertooth Aug 20 '10 at 13:24
1  
The mod_python project is officially dead. Ie., no longer developed or maintained and will not work as is with next Apache major version. Only works for current Linux distributions because they are patching it to even compile. See 'blog.dscpl.com.au/2010/06/…;. –  Graham Dumpleton Aug 21 '10 at 22:17
    
oh THanks a lot. I will try mod_wsgi –  sabertooth Aug 22 '10 at 4:56
1  
Hey @Graham, you are the guy who wrote mod_wsgi. Good job :) –  sabertooth Aug 23 '10 at 17:17
add comment

2 Answers 2

Here's what I'd suggest to do:

  1. Make sure you have both installed and enabled mod_python:

    $ sudo apt-get install libapache2-mod-python
    $ sudo a2enmod python
    $ sudo invoke-rc.d apache2 restart
    

  2. Put your site-specific configuration entries to a separate virtual host config file:

    $ cd /etc/apache2/sites-available
    $ sudo cp default python-site
    $ sudo a2ensite python-site
    

  3. Try commenting out CGI-specific settings leaving non-CGI settings along and see whether they
    1. Remove ScriptAlias /bin/ /home/aj/public_html/ line
    2. Remove +ExecCGI option from <Directory /home/aj/public_html/> section
    3. Remove AddHandler mod_python .py from <Directory /home/aj/public_html/> section
    4. Remove PythonHandler mod_python.cgihandler from <Directory /home/aj/public_html/> section
  4. Make sure /home/aj/public_html/old is in your PYTHONPATH, you may want to add it as follows:

    <Location "/home/aj/public_html/old/testing/">
        SetHandler python-program
        PythonHandler django.core.handlers.modpython
        PythonPath "['/home/aj/public_html/old'] + sys.path"
        PythonOption django.root /testing
        PythonDebug On
        SetEnv DJANGO_SETTINGS_MODULE testing.settings
    </Location>
    

  5. Don't forget to reload the configs for changes to take effect:

    $ sudo invoke-rc.d apache2 reload
    

Also, as topdog already mentioned I'd suggest to move to mod_wsgi or fcgi instead of mod_python which is considered deprecated.

share|improve this answer
    
Going to use mod_wsgi –  sabertooth Aug 23 '10 at 1:35
add comment

Change:

<Location "/home/aj/public_html/old/testing/">

to:

<Location "/testing">

That is meant to be the URL it is mounted at, not the physical directory.

You are also missing PythonPath directive so Python knows where to find your Django site.

The URL you would then access is 'http://localhost/testing'. Replace 'localhost' with name of host if not the box you are running browser on.

Have you read the Django documentation on mod_wsgi deployment on the Django site?

share|improve this answer
    
Going to use mod_wsgi. –  sabertooth Aug 23 '10 at 1:35
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.