Code Monkey home page Code Monkey logo

django-project-template's Introduction

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
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.


{{ 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.

django-project-template's People

Contributors

brutasse avatar magopian avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.