Skip to content

brutasse/django-project-template

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
env
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Django project template

This is the template I use for my projects.

Stack

Features

Usage

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
./install.sh

Then follow the instructions in the README file.

What follows is the README for projects created using this template.


{{ project_name|title }}

Setting up

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

Development

  • 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 with test.

Configuration

This template uses environment variables for configuration and application secrets. The required environment variables are:

  • SECRET_KEY: the secret key for Django
  • DATABASE_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.

Deployment

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.

About

The project template I use for my Django sites

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published