Created: 2012-03-21 18:08
Updated: 2017-01-12 12:30

Bada$$ Django Template

  • clean project structure
    • separate src directory for Django code
    • _site directory for web server document root
      • copied static files and user uploaded media files
      • works well with nginx's try_files directive
      • maintenance directory for toggling maintenance mode's
  • tested server configurations for nginx, uWSGI, and Supervisor
  • tiered settings for easier cross-environment support
    • for environment-independent settings
    • for environment-specific settings (not versioned)
    • for bringing them together and post-setup
  • template
  • a clean static directory for large Web app development
  • wicked hot Makefile for watching static files pre-processors:
    • make watch
    • CoffeeScript (requires Node and CoffeeScript)
    • SCSS (requires Ruby and Sass)
    • compiles scss => css
    • compiles coffee => javascript/src
  • integration with r.js
    • make optimize
    • includes file for single-file JavaScript optimization
    • compiles javascript/src => javascript/min
  • context processor for including JavaScript and CSS static urls
    • {{ CSS_URL }}
    • {{ JAVASCRIPT_URL }}
  • script in ./bin/ to output a SECRET_KEY for your
  • simple, but useful for common commands
  • ...HTML5 boilerplate hotness


  • Python 2.7 (because that's how we roll)

Fabfile Commands

  • mm_on - turns on maintenance mode
  • mm_off - turns off maintenance mode

Makefile Commands

  • build - builds and initializes all submodules, compiles SCSS and CoffeeScript and optimizes JavaScript
  • watch - watches the CoffeeScript and SCSS files in the background for changes and automatically recompiles the files
  • unwatch - stops watching the CoffeeScript and SCSS files
  • sass - one-time explicit recompilation of SCSS files
  • coffee - one-time explicit recompilation of CoffeeScript files

Local Settings is intentionally not versioned (via .gitignore). It should contain any environment-specific settings and/or sensitive settings such as passwords, the SECRET_KEY and other information that should not be in version control. Defining is not mandatory but will warn if it does not exist.

CoffeeScript/JavaScript Development

CoffeeScript is lovely. The flow is simple:

  • write some CoffeeScript which automatically gets compiled in JavaScript (assuming you did make watch)
  • when ready to test non-DEBUG mode, run make optimize

The file will need to be updated to define which modules should be compiled to single files. It is recommended to take a tiered approach to reduce overall file size across pages and increase cache potential for libraries that won't change for a while, for example jQuery.

SCSS Development

Sass is awesome. SCSS is a superset of CSS so you can use as much or as little SCSS syntax as you want. It is recommended to write all of your CSS rules as SCSS, since at the very least the Sass minifier can be taken advantage of.

Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more