Everyone who has worked with Django for any reasonable period of time comes to the realization that starting up a new project can be a pain in the butt if you don’t build some level of automation into the process. After a few times copy and pasting into your <pre>settings.py</pre> most developers decide they can’t handle it any more and write some scripts to take care of the setup process for them.
I thought I would share my setup script, recently modified, and hopefully it will be helpful to those who are still in copy and past land.
First, my basic setup for most django projects I start is as follows:
1) create a new virtual environment with virtualenv
2) install django within the environment and start a new project
3) remove database setup, static media setup and debug settings from the auto generated settings.py file.
4) Add debug_toolbar settings, a dynamic media path, dynamic template_dir path, django_evolution or south and an import of a settings_local.py file to the settings.py file.
5) Create a settings_local.py file that defines local database connection, static media path and debug settings.
6) Modify the urls.py file to handle your static and media directories correctly.
7) Create a new sublime text project containing the new django project.
8) Initialize the django project as a git repo and create a .gitignore file.
9) Create a deploy script to ssh into production and git pull from github.
10) Get started actually building my app
Do this once or twice and you start to understand why many prefer customization over configuration. But if you’re a Django lover like myself you find a way around it.
So I built this quick and dirty script to do all of this for me:
This calls to a templates directory that has a settings.py settings_local.py and deploy.sh templates.
A few other things to note: most actions are called as subprocesses directly to the command line rather than using wrapper libraries primarily out of laziness. When replacing the settings file it is important to remember to regenerate the secrete_key. The deploy script is not an integration script. For most of my personal projects I run tests locally and push to github for integration.