You are here: Foswiki>TIG Web>WebServices>DjangoApplications (revision 3)EditAttach

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. ssh to the web server that will serve your content, as listed at WebServerArchitecture
  2. 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.)
  3. django-admin startproject YOUR_APP_NAME
  4. 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
  5. 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")
  6. chmod 755 index.fcgi
  7. 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]
  8. Visit and hopefully see Welcome to django! and follow along with database setup in Django's tutorial

To set up a database, see the Databases section of WebServices.
Edit | Attach | Print version | History: r5 | r4 < r3 < r2 < r1 | Backlinks | View wiki text | Edit WikiText | More topic actions...
Topic revision: 30 May 2012, ArthurProkosch

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