Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.mkd

Django Base Template

Goals

  1. Start with a working deploy config.
  2. Pre-configure the apps that we use on every project.
  3. Follow best practices and conventions wherever possible.
  4. Develop with the same environment as the production server, from any machine.
  5. Provide useful fabric scripts for managing remote servers.

Assumptions

This project assumes that you want to use the following:

Project Initialization

With Django 1.4, you can use the new project template feature. From the console: django-admin.py startproject --template=https://github.com/lynndylanhurley/django-base-template/tarball/master --extension=py,mkd project_name Where project_name is the name of your app.

Otherwise you can just fork this repo and manually change any instances of {{ project_name }} to the name of your app. This variable exists in the following files:

  • README.mkd
  • environments.py
  • deploy/common_settings.py
  • deploy/settings.py

Remove everything above this line.


{{ project_name }}

Requirements

This project requires the following:

  1. An Ubuntu 10.04 server
  2. Vagrant
  3. pip

Included Apps


Initial setup

pip install fabric
vagrant up
fab dev bootstrap

This will take awhile (like, awhile). You may be prompted for input during the fab dev bootstrap step, so you will need to bear it out.

When the initial setup is finished, you will have a running server instance at localhost:8888.

Development

Use vagrant to manage the dev server. Commands include:

  • vagrant up: start server
  • vagrant reload: reload server
  • vagrant suspend: suspend server
  • vagrant destroy: destroy VM (useful for testing the bootstrap command)
  • vagrant ssh: shell into dev server

Get the full list of commands by running vagrant -h

Local Development Server

To access django's local dev server, you have two options - you can spend several hours setting up your MacBook (and helping everyone else on the project get set up), or you can use the environment that we've already built from inside the Vagrant VM.

If you choose the latter option, follow these instructions:

vagrant ssh
cd $VAGRANT_ROOT
workon $PROJECT_NAME
./manage.py runserver_plus 0.0.0.0:8000

You should now be able to access the local dev server on localhost:8000

Deployment

This project uses fabric for deployment + provisioning. Several commands are already included (replace 'xxx' with the name of your env from environments.py):

  • fab xxx bootstrap: Install dependencies, deploy initial app to xxx.
  • fab xxx deploy: Deploy latest git commit to xxx server.
  • fab xxx rollback: Roll back to previous deploy on xxx.

Note:

  • Do NOT use sudo when running pip commands. We use pythonbrew to avoid that mess.
  • Nginx, uWSGI, and Postgres run as the user specified in environments.py

Organizational Conventions

Settings

Settings that are common to each environment are specified in deploy/common_settings.py. For example, each environment will share the base INSTALLED_APPS list, so that is defined in deploy/common_settings.py.

Each environment will have its own unique settings (i.e. DEBUG). These settings should be defined in deploy/settings.py.

Directory Structure

conf/

This directory contains configuration templates that will be formatted with the local settings for the target server.

deploy/

Files in this directory are pushed to the target server when running fab xxx deploy.

deploy/apps/

This is where to place apps created with the django-admin.py startapp command.

deploy/assets/

Static assets, to be collected upon ./manage.py collectstatic.

deploy/lib/

For miscellaneous helper scripts that don't belong to any particular app.

deploy/static/

This folder will contain the files generated by ./manage.py collectstatic. This directory is git-ignored, and the static collection takes place on the server upon deployment.

deploy/templates/

Django template overrides.

deploy/uploads/

File uploads for local development. This directory is git-ignored - each server will have its own persistent uploads folder.

fabutils/

Useful fabric scripts.

Something went wrong with that request. Please try again.