You are here: Foswiki>TIG Web>WebServices>DjangoApplications (revision 2)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, ...

Setup

These instructions are adapted from http://wiki.apisnetworks.com/index.php/Django_Quickstart and https://docs.djangoproject.com/en/1.3/howto/deployment/fastcgi/ to fit CSAIL's Debian-based shared hosting environment. Please replace the variables SAMPLE_PROJECT, 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. For example, /afs/csail/proj/SAMPLE_PROJECT/www/private
  3. django-admin startproject YOUR_APP_NAME
  4. Create the web-accessible directory that will be dedicated to this application. For example, /afs/csail/proj/SAMPLE_PROJECT/www/data/YOUR_APP_NAME
  5. Create index.fcgi inside that directory:
    #!/usr/bin/python
    import sys, os
     
    # Add the application's parent directory
    sys.path.append("/afs/csail.mit.edu/PATH/TO/PRIVATE/YOUR_APP_NAME")
     
    # Set the DJANGO_SETTINGS_MODULE environment variable.
    os.environ['DJANGO_SETTINGS_MODULE'] = "myapp.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
    RewriteBase /WEB/PATH/TO/YOUR_APP_NAME
    RewriteRule ^$ index.fcgi/ [QSA,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.fcgi/$1 [QSA,L]
  8. Visit http://SERVER.csail.mit.edu/WEB/PATH/TO/YOUR_APP_NAME 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: 09 Feb 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