You are here: Foswiki>TIG Web>WebServices>DjangoApplications (revision 4)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_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:
    #!/usr/bin/python
    import sys, os
     
    # Add the application's parent directory. Modify everything after /afs/csail.mit.edu/ below:
    sys.path.append("/afs/csail.mit.edu/group/SAMPLE_GROUP/www/private")
     
    # 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
    RewriteBase /WEB/PATH/TO/END_OF_PUBLIC_URL
    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/END_OF_PUBLIC_URL and hopefully see Welcome to django! and follow along with database setup in Django's tutorial

Troubleshooting

To set up a database, see the Databases section of WebServices.
Edit | Attach | Print version | History: r5 < r4 < r3 < r2 | Backlinks | View wiki text | Edit WikiText | More topic actions...
Topic revision: 09 Jul 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