Django Applications

Python's django framework allows efficient development of web applications. The packages python-django and python-flup are installed on the main CSAIL web servers, as well as FastCGI support. TIG cannot provide much troubleshooting help beyond directions for examining WebServerLogs.

The following notes are provided in case they allow future python hackers to get started more quickly. Please update them with fixes, tips, ...


These instructions are adapted from and to fit CSAIL's Debian-based shared hosting environment. Please replace the variables SAMPLE_GROUP, YOUR_APP_NAME, /PATH/TO/HERE, etc with their actual values.

  1. For most Django applications, you'll want a database. See the Databases section of WebServices for information on setting that up.
  2. ssh to the web server that will serve your content, as listed at WebServerArchitecture
  3. Identify a directory outside of the documentroot and cd into it. This will be the parent directory for the application's code. For example, /afs/csail/group/SAMPLE_GROUP/www/private (This directory's AFS permissions must include www rl.)
  4. django-admin startproject YOUR_APP_NAME
  5. Create the web-accessible directory that will be dedicated to this application. For example, /afs/csail/group/SAMPLE_GROUP/www/data/END_OF_PUBLIC_URL
  6. Create index.fcgi inside that directory:
    import sys, os
    # Add the application's parent directory. Modify everything after /afs/ below:
    # Set DJANGO_SETTINGS_MODULE to match the final (child) directory containing the app
    os.environ['DJANGO_SETTINGS_MODULE'] = "YOUR_APP_NAME.settings"
    from django.core.servers.fastcgi import runfastcgi
    runfastcgi(method="threaded", daemonize="false")
  7. chmod 755 index.fcgi
  8. Create .htaccess inside that directory:
    AddHandler fastcgi-script .fcgi
    RewriteEngine On
    RewriteRule ^$ index.fcgi/ [QSA,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.fcgi/$1 [QSA,L]
  9. Visit and hopefully see Welcome to django! and follow along with database setup in Django's tutorial


If you have more detail to add, or find solutions to other problems you have with your Django apps at CSAIL, please add to this section!
  • If you get a 500 Internal Server Error when loading, first check /var/log/apache2/error.log for clues. You may continue to get Error 500s after fixing the problem for up to one day, due to caching in FastCGI. To get things working sooner, email so we can service reload apache2.
  • As we migrate our web servers from Debian Squeeze to Ubuntu Precise you may notice problems due to the bump in Python and/or Django versions:
    • If you get error messages saying things like 'AdminSite' object has no attribute 'root', you'll need to change your code to use instead of (Here's a discussion of the change from 2009, when it was new.)
    • django.utils.log.RequireDebugFalse no longer works. I (Jay) am afraid I'm not conversant enough to Django to understand the problem or its workaround ó the person in whose code we noticed this wasnít using logging at all, so he just deleted the setting ó but Iíve seen claims (for instance here and here) that the thing to do is either comment out the LOGGING section in or to paste in the appropriate config from a corresponding global file.
Topic revision: 23 Apr 2014, JaySekora

MIT Computer Science and Artificial Intelligence Laboratory


  • About CSAIL
  • Research
  • News + Events
  • Resources
  • People

This site is powered by Foswiki MIT: Massachusetts Institute of Technology