scripts.mit.edu

MIT SIPB Script Services for Athena

How do I upgrade Django? Can I still use the Django quickstart if I do so?

Currently, the Scripts servers provide Django version 1.6.10, which is no longer supported by the Django maintainers. You can, however, install your own updated copy of Django in your locker, run the Scripts quick-start installer, and modify some files to have a working quick-start project. These instructions should work equally well with both your own locker and a locker under your control.

Disclaimer: this guide was written with an install of Django 1.10.5.

Install an updated version of Django

First, from an Athena prompt:

$ add consult
$ mkdir -p /mit/[lockername]/.local/
$ fsr sa /mit/[lockername]/.local/ daemon.scripts write

These commands give the Scripts daemon access to the subdirectory where the Django install is going to be.

Then, ssh into scripts

$ ssh -k [lockername]@scripts

Finally, upgrade Django for your locker only:

$ pip install --user --upgrade django

You can test if this upgrade worked by running:

$ python -c "import django; print(django.get_version())"

(If it works you should see the current Django version, instead of the old Scripts Django version.)

Run the quick-start

From an Athena prompt, now run the Django quick-start installer for your locker. (You don’t need to be ssh’d into a Scripts server to do this.)

There are two things you are allowed to choose as part of the setup process. The first is the address that you can access your Django website at (such as [lockername].scripts.mit.edu/[path]) and the second is the code name for your project (such as [django-app]). We will refer to your choices, [path] and [django-app], in the next section.

The Django quick-start installer sets up files that allows your Django app to run on the Scripts servers using fastcgi; however, the installer was written with Django 1.6.10 in mind. We have to modify some of the files produced by the installer in order for them to work with Django 1.10.

Modify quick-start produced files

/mit/[lockername]/web_scripts/[path]/index.fcgi

The first file we will modify is index.fcgi, which runs whenever a user attempts to access your website.

After the

os.environ['DJANGO_SETTINGS_MODULE'] ...
line, add the following:
import django
django.setup()

Delete the following lines:

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")

At the end of the file, add the following lines:

from flup.server.fcgi import WSGIServer
from django.core.handlers.wsgi import WSGIHandler
WSGIServer(WSGIHandler()).run()

/mit/[lockername]/Scripts/django/[django-app]/[django-app]/settings.py

Add your hostname to the ALLOWED_HOSTS list in settings.py.

ALLOWED_HOSTS = ["[lockername].scripts.mit.edu"]

You should now get a page at [lockername].scripts.mit.edu/[page] that says “It worked!”.

Previous:
Next:
© 2004-2020, the SIPB scripts.mit.edu project.
These pages may be reused under either the GFDL 1.2 or CC-BY-SA 3.0.
Questions? Contact scripts@mit.edu.

You are currently connected to busy-beaver.mit.edu.