Notes on my new Django setup
My personal record of using revision control for source code has been pretty spotty. Today I took steps toward fixing that by working out a system for managing my Django projects. I wanted revision control (Subversion), I wanted Django’s “runserver” for development and mod_python for deployment, and I didn’t want it to be a pain.
Some highlights of the process:
-
I used my pastebin site as the test mule. I checked in the current live site’s source code, created “trunk”, “tags”, and “branches” directories per the Subversion manual, and checked out a copy of the trunk into a staging directory.
-
I used
svn propedit svn:ignoreto keep the project’s SQLite database file out of the repository. Via my~/subversion/configfile I also ignore few other things such as .pyc files, just so thatsvn statuschecks aren’t littered with question marks on those files. -
I created a simple
runserver.shscript that sets $PYTHONPATH (so that imports likefrom pasteproject import settingsfind the staging version, not my deployed version!) and starts the Django development server. -
Tricky Django thing #1: I use the conditional URLconf trick in order to correctly serve media files when using the development server. The docs on this trick go on to say; “the catch here is that you’ll have to remember to set DEBUG=False in your production settings file.” Which brings me to…
-
Tricky Django thing #2: Modular settings. The first line of
settings.pyis:from pasteproject.settings_local import DEBUG, TEMPLATE_DEBUG, PROJECT_BASE. The filesettings_local.pyis not under version control, and is of course different for the development and deployment versions. It’s only two lines; the first line setsDEBUGandTEMPLATE_DEBUGtoTrue(development) orFalse(deployment); the custom settingPROJECT_BASEis used to locate the correct SQLite database file and the media files.