A heavily personalized project template for Django 1.7 using postgres for development and production. Ready to deploy on Heroku with a bunch of other goodies.
Forked from the original django-two-scoops-project
Prerequisites: python, django
To create a new Django project, run the following command replacing {{ project_name }}
with your actual project name:
django-admin.py startproject --template=https://github.com/imkevinxu/django-kevin/archive/master.zip --extension=py,md,html,json,coveragerc --name=Procfile,Procfile.dev {{ project_name }}
Prerequisites: virtualenv, virtualenvwrapper
cd {{ project_name }}
mkvirtualenv {{ project_name }}-dev && add2virtualenv `pwd`
mkvirtualenv {{ project_name }}-prod && add2virtualenv `pwd`
For development:
workon {{ project_name }}-dev
pip install -r requirements/local.txt
For production:
workon {{ project_name }}-prod
pip install -r requirements.txt
Prerequisites: node, homebrew
sudo npm install
In order to be able to lint SCSS files locally you need ruby
on your local system and a certain gem. See https://github.com/ahmednuaman/grunt-scss-lint#scss-lint-task
gem install scss-lint
In order for grunt to notify you of warnings and when the build is finished, you need a notification system installed. Below is the Mac OSX notification command-line tool
brew install terminal-notifier
The environment variables for development sets the appropriate DJANGO_SETTINGS_MODULE and PYTHONPATH in order to use django-admin.py seemlessly. Necessary for Foreman and other worker processes
.env.dev is not version controlled so the first person to create this project needs to create a .env.dev file for Foreman to read into the environment. Future collaboraters need to email the creator for it.
echo DJANGO_SETTINGS_MODULE=config.settings.local >> .env.dev
echo PYTHONPATH={{ project_name }} >> .env.dev
echo PYTHONUNBUFFERED=True >> .env.dev
echo CACHE=dummy >> .env.dev
Prerequisites: Postgres and Heroku Toolbelt
Install Postgres for your OS here. For Max OSX the easiest option is to download and run Postgres.app.
# Make sure Postgres.app is running
workon {{ project_name }}-dev
createdb {{ project_name }}-dev
foreman run django-admin.py migrate
Recommended to use foreman to start processes:
By default, .foreman uses the development versions of .env and Procfile
foreman start
Create a local super user with:
foreman run django-admin.py createsuperuser
To run one-off commands use:
foreman run django-admin.py COMMAND
To enable Live Reload, download and turn on a browser extension.
The environment variables for production must contain a separate SECRET_KEY for security and the appropriate DJANGO_SETTINGS_MODULE and PYTHONPATH in order to use django-admin.py seemlessly. Hacky use of date | md5
to generate a pseudo-random string.
.env is not version controlled so the first person to create this project needs to create a .env file for Foreman and Heroku to read into the environment. Future collaboraters need to email the creator for it.
echo "SECRET_KEY=`date | md5`" >> .env
echo "DJANGO_SETTINGS_MODULE=config.settings.production" >> .env
echo "PYTHONPATH={{ project_name }}" >> .env
echo "WEB_CONCURRENCY=3" >> .env
echo "PYTHONUNBUFFERED=True" >> .env
echo "BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git" >> .env
Prerequisites: Heroku Toolbelt and heroku-config
First step is to deploy to Heroku with the post_compile
script in bin/ so that node functions can be installed for python to call them.
git init
git add .
git commit -m "ready for heroku deploy"
heroku create
heroku config:push
git push heroku master
After post_compile
is successful, uncomment line 205 in /{{ project_name }}/config/settings/base.py
with the variable STATICFILES_STORAGE
to enable django-pipeline.
git commit -am "enabled django-pipeline"
git push heroku master
heroku open
If you're sure all database migrations are in good condition, migrate models with:
heroku run django-admin.py migrate
To run one-off commands use:
heroku run django-admin.py COMMAND
Make sure to edit the .foreman file to use production versions of .env and Procfile
This is meant to mimic production as close as possible using both the production database and environment settings so proceed with caution.
WARNING: If this project has SSL turned on, localhost:5000 won't work anymore because it will always try to redirect to https://localhost:5000. To fix this comment out the SECURITY CONFIGURATION section of production.py
lines 66-85.
workon {{ project_name }}-prod
pip install -r requirements.txt
heroku config:pull
foreman run django-admin.py collectstatic --noinput
foreman start
The site will be located at localhost:5000.
Grunt automatically compiles Jasmine tests written in coffeescript at /{{ project_name }}/static/js/tests/coffee
and runs the tests upon every save.
Grunt also creates a static file server to view the results of the test located at localhost:9000/tests/jasmine.html.
Enable SSL via Heroku, Cloudflare, or your DNS provider and then uncomment lines 84-108 in /{{ project_name }}/config/settings/production.py
to enable django-secure security best practices for production.
In order to enable redis for caching and queues, add Redis Cloud to Heroku.
heroku addons:add rediscloud:25
Turn on background job worker queue with this one-liner:
heroku scale worker=1
To use Amazon S3 as a static and media file storage, create a custom Group and User via IAM and then a custom static bucket and media bucket with public read policies.
Add the following config variables to Heroku:
heroku config:set AWS_ACCESS_KEY_ID=INSERT_ACCESS_KEY_ID
heroku config:set AWS_SECRET_ACCESS_KEY=INSERT_SECRET_ACCESS_KEY
heroku config:set AWS_STATIC_STORAGE_BUCKET_NAME={{ project_name }}-static
heroku config:set AWS_MEDIA_STORAGE_BUCKET_NAME={{ project_name }}-media
Currently using Django 1.7 for the app framework
- South 1.0 - database migrations
- bpython 0.13.1 - advanced python interpreter/REPL
- defusedxml 0.4.1 - Secure XML parser protected against XML bombs
- dj-static 0.0.6 - serve production static files with Django
- django-authtools 1.0.0 - custom User model classes such as
AbstractEmailUser
andAbstractNamedUser
- django-braces 1.4.0 - lots of custom mixins
- django-extensions 1.3.9 - useful command line extensions (
shell_plus
,create_command
,export_emails
) - django-floppyforms 1.2.0 - control of output of form rendering
- django-model-utils 2.2 - useful model mixins and utilities such as
TimeStampedModel
andChoices
- django-pipeline 1.3.25 - CSS and JS compressor and compiler. Also minifies HTML
- django-redis 3.7.1 - enables redis cacheing
- logutils 0.3.3 - Nifty handlers for the Python standard library’s logging package
- project-runpy 0.3.1 - Helpers for Python projects like ReadableSqlFilter
- psycopg2 2.5.3 - PostgreSQL adapter
- python-magic 0.4.6 - Library to identify uploaded file's headers
- pytz 2014.4 - world timezone definitions
- requests 2.4.0 - HTTP request API
- rq 0.4.6 - background tasks using redis as queue
- static 1.0.2 - serves static and dynamic content
- unicode-slugify 0.1.1 - A slugifier that works in unicode
- Werkzeug 0.9.6 - WSGI utility library with powerful debugger
- django-debug-toolbar 1.2.1 - debug information in a toolbar
- django-sslserver 0.12 - SSL localhost server
- Collectfast 0.2.0 - Faster collectstatic
- boto 2.32.1 - Python interface to AWS
- dj-database-url 0.3.0 - allows Django to use database URLs for Heroku
- django-secure 1.0 - Django security best practices
- django-storages 1.1.8 - custom storage backends; using S3
- gunicorn 19.1.0 - production WSGI server with workers
- coverage 3.7.1 - measures code coverage
- flake8 2.2.3 - Python style checker
Using post_compile
script for the Heroku python environment to recognize node packages
- yuglify 0.1.4 - uglifyJS and cssmin compressor
Locally using node and grunt to watch and compile frontend files
- coffee-script ^1.8.0 - Cleaner JavaScript
- grunt ~0.4.5 - Automatic Task Runner
- grunt-autoprefixer ^1.0.1 - Parse CSS and add vendor-prefixed CSS properties
- grunt-coffeelint 0.0.13 - Lint your CoffeeScript
- grunt-concurrent ^1.0.0 - Run grunt tasks concurrently
- grunt-contrib-clean ^0.6.0 - Clear files and folders
- grunt-contrib-coffee ^0.11.1 - Compile CoffeeScript files to JavaScript
- grunt-contrib-connect ^0.8.0 - Start a static web server
- grunt-contrib-copy ^0.6.0 - Copy files and folders
- grunt-contrib-imagemin ^0.8.1 - Minify PNG, JPEG, GIF, and SVG images
- grunt-contrib-jasmine ^0.8.0 - Run jasmine specs headlessly through PhantomJS
- grunt-contrib-watch ^0.6.1 - Run tasks whenever watched files change
- grunt-newer ^0.7.0 - Configure Grunt tasks to run with changed files only
- grunt-notify ^0.3.1 - Automatic desktop notifications for Grunt
- grunt-sass ^0.14.1 - Compile Sass to CSS
- grunt-scss-lint ^0.3.3 - Lint your SCSS
- grunt-template-jasmine-istanbul ^0.3.0 - Code coverage template mix-in for grunt-contrib-jasmine, using istanbul
- grunt-text-replace ^0.3.12 - General purpose text replacement for grunt
- load-grunt-config ^0.13.1 - Grunt plugin that lets you break up your Gruntfile config by task
- time-grunt ^1.0.0 - Display the elapsed execution time of grunt tasks
- SS-Standard 1.005 - Standard icon library as a font. Documentation located locally at
/{{ project_name }}/static/css/fonts/ss-standard/documentation.html
- Bootstrap 3.2.0 - CSS/JS starting framework
- Bootstrap 3.2.0 - CSS/JS starting framework
- Underscore.js 1.7.0 - Very useful functional programming helpers
- CSRF.js - Django Cross Site Request Forgery protection via AJAX
- Jasmine-Ajax 2.0.1 - Set of helpers for testing AJAX requests with Jasmine
- Jasmine-jQuery 2.0.5 - Set of jQuery helpers for Jasmine
This project follows best practices as espoused in Two Scoops of Django: Best Practices for Django 1.6.
- Daniel Greenfield and Audrey Roy for writing the book
- Randall Degges for django-skel
- All of the contributors to the original fork