This is the template I use for my projects.
setup.py
for deployment using real packages. Do yourself a favor, don't use VCS for deployments.- Local development with Foreman.
- Configuration entirely based on environment variables (no code changes when your deploy).
- SCSS/compass with simplified Frameless by @idan for layout management, responsive-ready.
- Integrated apps:
- django-discover-runner
- django-floppyforms
- django-ratelimit-backend
- django-redis-cache
- django-sekizai
- raven
- And for development (in
requirements-dev.txt
):
To create a project using this template:
mkvirtualenv -p python2 project_name
workon project_name
pip install Django
django-admin.py startproject --template=https://github.com/brutasse/django-project-template/zipball/master --extension=py,rst,template project_name
cd project_name
find . -iname "*.template" -exec rename -v ".template" "" {} \;
pip install -r requirements.txt && pip freeze -l > requirements.txt
Then follow the instructions in the README file.
What follows is the README for projects created using this template.
cd /path/to/project
add2virtualenv .
gem install bundle
bundle install
pip install -r requirements-dev.txt
createdb -U postgres {{ project_name }}
make syncdb
make test
Running the development server & compass:
foreman start
If you need more processes (queue workers, stub mail servers or other things), add them to the
Procfile
.Running the tests:
make test
Tests are located in the
tests/
directory. Create files at will, the test runner will auto-detect tests if the file names begin withtest
.
This template uses environment variables for configuration and application secrets. The required environment variables are:
SECRET_KEY
: the secret key for DjangoDATABASE_URL
: a heroku-like database URL.
Optionally you can use:
DEBUG
: set it to something non-empty to switch to a development environment. Obviously, don't set it in production.SENTRY_DSN
: your DSN for sending exceptions and 404's to Sentry.REDIS_URL
: a heroku-like URL to configure redis. If you set it, redis will be used as a cache backend and the message and session storage engines will use it whenever possible.
Environment varibles are defined using the env
directory. To set an environment variable, add a file to the env
directory with the appropriate content. When you run any command in your project, manage.py
reads the files in env
and exposes them as environment variables.
This replicates the behaviour of Daemontools's envdir
program, which you can use in production to set environment variables properly.
Do not use foreman
to deploy apps created this way. Run setup.py sdist
, export the distribution to your own PyPI server and use pip
to install it on your production machines. Or convert the python distribution to a system package if you prefer.
Use daemontools
's envdir
program to manage application secrets (SECRET_KEY
, DATABASE_URL
, SENTRY_DSN
, etc.).
Use a process watcher such as supervisor
or circus
to run the web server. Example:
envdir /path/to/config /path/to/env/bin/gunicorn {{ project_name }}.wsgi -k gevent -b 127.0.0.1:8000 -w 2
The combination of envdir
and an installable package makes it extremely simple to automate your deployments.