Support deploying to subfolder.

The bulk of this just changes the URLs to be relative so people can
deploy to subfolders via the `APPLICATION_ROOT` setting.

Changes included:
- cleaned up redundant config settings
- support for instance configs
- fixed request permalinks
- minor PEP8 tweaks