cs304 logo

Admin

Plan

  1. Introduce Django.
  2. Address those questions
  3. Describe some important infrastructure:
  4. Let Sarah Xu take over
  5. Grab bag of other topics, but probably not. Maybe only atpworldtour.com, schedule for Madrid Open, 2015

Django

Django questions

Address your questions

Ports

With Django, as with node.js, you're not extending an existing HTTP server, as we are with Apache or Tomcat. You're responsible for the entire server. You open up a port to do so.

For today, you'll each be running on your own Mac, so there's no trouble. We can all use port 8000 (the Django default).

Note that this is one reason, among several, that I haven't switched to Django for this course. I want to figure out a smooth way to integrate a Django-powered site with Apache-powered Tempest (and other servers).

Django Tutorial Resource

The following is a good start: Django Book. It's out of date, but still an excellent introduction to the ideas and infrastructure, which I think is sadly lacking from other tutorials.

Background Knowledge: Virtualenv

Separate from Django but crucial in the same way that plumbing is separate from opening a store.

Virtualenv is a way to allow you, the user, to install a set of Python packages for a particular project.

This is really cool!

  1. On your classroom Mac, start a terminal
  2. Use the virtualenv command; it should exist and tell you its usage.
  3. Do virtualenv kittens or some other project name. This creates a kittens directory with a bunch of stuff in it for your kittens project.
  4. Do cd kittens and ls. Look around. Look in bin.
  5. Do printenv VIRTUAL_ENV and printenv PATH. Do which python Do:
    python
    >>> import sys, pprint
    >>> pprint.pprint(sys.path)
    >>> quit
    
  6. Do source bin/activate. (Maybe in a second shell.)
  7. Repeat the printing of VIRTUAL_ENV, and PATH and its effect on PYTHONPATH.

Background Knowledge: Pip

Pip is another bit of Python plumbing. It allows you to

With virtualenv, pip installs to the activated project, rather than to system-wide directories. Usually, you couldn't use it; now you can!

  1. In an activated project, do pip install django
  2. do an ls on the lib/python2.7/site-packages directory.
  3. run python, and do import django

Background Knowledge: SQLite

SQLite is a SQL-based DBMS in a single file. This is nice because you can easily copy your database from place to place, it's easily locked, etc. This is the default back-end DBMS for Django.

Turning it Over

I'm now going to turn the class over to Sarah Xu, who took 304 last year and did an independent study using Django this term.

She wrote this handout for us.

She also provided this zip file for us.

Summary