Django Heroku Skeleton
A Django skeleton for Django 1.10.3. Build for work with Heroku. In just 15 minutes you get a running Django instance on Heroku.
In this readme replace:
- myproject with your project name
- myapp with your app name
- yoursecretkey with your secret key
- myapplink with your Heroku link
- herokuappname with the name from your Heroku instance
- githubname with your GitHub username
- githubrepo with the name from your (new) repo
- privatesentrydsn with your private Sentry dsn from sentry.io
- publicsentrydsn with your public Sentry dsn from sentry.io
- Install Windows PowerShell Link
- Install Python 3 Link
- Install pylauncher Link
- Install Heroku Toolbelt Link
- Install and configure git Link
Open PowerShell as Administrator and execute
answer with yes. Close Powershell. (Necessary for virtualenv)
Open PowerShell with normal limited rights.
Login into Heroku
pip install virtualenv
Install actual Django version
pip install django
1. Let's start
Navigate in the console to the folder where you want to have your Django project. Then create your project and your app.
django-admin startproject --template=https://github.com/WoHinDu/django-heroku-skeleton/archive/master.zip --name Procfile,requirements.txt myproject cd myproject python manage.py startapp myapp
myproject\settings\base.pyin your editor and add
'myapp.apps.MyappConfig',in the first line from
INSTALLED_APPS. Note: You have to replace myapp 2x times.
myproject\settings\prod.pyin your editor and replace
myproject\settings\dev.pyin your editor and replace
Remove unnecessary stuff
Create folder for static assets and templates
mkdir myapp\templates mkdir myapp\static
Create a virtualenv called "venv"
To deactivate it later just type:
Install required stuff
pip install -r myproject/reqs/dev.txt
2. Run your site
python manage.py migrate
Spin up the development server
python manage.py runserver
Open it in your web browser and enjoy it :)
3. Deploy to Heroku
Create empty git repo
Create Heroku app
heroku create myproject --region eu
Create new GitHub repo at github.com. Then connect it with your new local git repo.
git remote add github email@example.com:githubname/githubrepo.git
git config -e the configuration file from your local git repo and
add at the end the following:
[remote "origin"] pushurl = firstname.lastname@example.org:githubname/githubrepo.git pushurl = https://git.heroku.com/herokuappname.git
You are now able to push with just one command your stuff to GitHub and Heroku.
myproject\settings\prod.py and copy your Heroku-app link in
ALLOWED_HOSTS = ['.myapplink'].
The leading dot is important! (Without https://)
Set environment variables in Heroku
heroku config:add SECRET_KEY=yoursecretkey heroku config:add DJANGO_SETTINGS_MODULE=myproject.settings.prod
Create an account at sentry.io. Create an organisation and project. Then add your Sentry DNS code as an environment variable.
heroku config:add SENTRY_DSN=privatesentrydsn
temlates/500.html and replace
publicsentrydsn with your public DSN from Sentry.
Note: Sentry is also available as a Heroku Addon, but unfortunately no longer as a free version.
Add Heroku modules. I choose for every module the free plan, but this can change from time to time. Please check it twice at Heroku.
Deploy Postgres. An amazing database. For more info see Postgres
heroku addons:create heroku-postgresql:hobby-dev
Deploy Papertrail. Allows you to view the logs from your app/Heroku. For more info see Papertrail
heroku addons:create papertrail:choklad
Deploy Sendgrid. It allows you to send emails. For more info see Sendgrid
heroku addons:create sendgrid:starter
Deploy Librato. It monitors everything on Heroku for you. For more info see Librato
heroku addons:create librato:development
Add anything to git, commit and push it.
git add -A git commit -m "Initial commit" git push origin master
Now go to
and connect your GitHub repo with Heroku.
heroku run python manage.py migrate
Create a superuser for your project
heroku run python manage.py createsuperuser
Finished! Enjoy your new Heroku site. If you have any remarks, improvements or anything else, I'm happy about every pull request/opened issue!
Now you have a running Django instance on Heroku. That means you can start developing your project. If you are satisfied with django-heroku-template, you can now stop configuring and start coding. If not, here a few ideas, who are maybe helpful for you:
- edit the settings files to your preferred settings
- Localise your project
- Setup your own domain
- Add your own SSL certificate
- Set up a continuous integration system like Travis
- Link Sentry with your GitHub repo and activate release tracking
- Use a Content-Delivery Network with WhiteNoise
- Include caching and compressing
- Use an asynchronous task queue like Celery in connection with CloudAMQP
- Serve your static assets via Amazon S3
I borrowed a few ideas from guys who are a way more familiar with Python and Django than I am. Thanks to: