Building a Django
App on Heroku
Get your project up and running in 20 minutes
or less.
What is Heroku?
● Platform-as-a-Service (PaaS)
● Acquired by salesforce.com in 2010
Why Heroku?
●
●
●
●

Focus on developer productivity
100% free plan includes hosting & db
No need to think about servers
E...
Why we chose Heroku
● Free to start
● No bandwidth/budget for devops
● Flexibility to deploy elsewhere in future if
needed
Prerequisites
Familiarity with:
● command line
● git
Prerequisites
Install:
● pip
http://www.pip-installer.org
● Postgres
pip install psycopg2
http://initd.org/psycopg/
Prerequisites
Install:
● Virtualenv
pip install virtualenv
Getting Started
1. Sign up for a Heroku account at Heroku.com
2. Install Heroku Toolbelt: https://toolbelt.heroku.com
3. L...
Create a Django app locally
$
$
$
$
$

mkdir mysite && cd mysite
virtualenv venv --distribute
source venv/bin/activate
pip...
Create a Procfile
Create a Procfile in your root project directory:
# Procfile
web: gunicorn hellodjango.wsgi
Create requirements.txt
$ pip freeze > requirements.txt
Note: If you do this out of order, you’ll need to
manually create ...
Modify settings.py
import dj_database_url
DATABASES['default'] =

dj_database_url.config()

SECURE_PROXY_SSL_HEADER = ('HT...
Modify wsgi.py
from django.core.wsgi import get_wsgi_application
from dj_static import Cling
application = Cling(get_wsgi_...
Store your app in git
First create a .gitignore file; add:

venv
*.pyc
staticfiles
Store your app in git
Initialize a new git repository
$ git init
Add the new files
$ git add .
Commit your files
$ git com...
Push your code to Heroku
Create a new app on Heroku
$ heroku create
Deploy your code to Heroku
$ git push heroku master
Start your app

Each Heroku
app comes
with 1 free
dyno.

Start a Heroku dyno
$ heroku ps:scale web=1
Scaling dynos... done...
Visit your app
$ heroku open
Visit your app
Congrats! You’ve set up a live Djangopowered application via Heroku.
Upcoming SlideShare
Loading in …5
×

Building a Django App on Heroku

543 views

Published on

A quick overview on how to build a Django app on the Heroku platform

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
543
On SlideShare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Building a Django App on Heroku

  1. 1. Building a Django App on Heroku Get your project up and running in 20 minutes or less.
  2. 2. What is Heroku? ● Platform-as-a-Service (PaaS) ● Acquired by salesforce.com in 2010
  3. 3. Why Heroku? ● ● ● ● Focus on developer productivity 100% free plan includes hosting & db No need to think about servers Easily scales
  4. 4. Why we chose Heroku ● Free to start ● No bandwidth/budget for devops ● Flexibility to deploy elsewhere in future if needed
  5. 5. Prerequisites Familiarity with: ● command line ● git
  6. 6. Prerequisites Install: ● pip http://www.pip-installer.org ● Postgres pip install psycopg2 http://initd.org/psycopg/
  7. 7. Prerequisites Install: ● Virtualenv pip install virtualenv
  8. 8. Getting Started 1. Sign up for a Heroku account at Heroku.com 2. Install Heroku Toolbelt: https://toolbelt.heroku.com 3. Log in via command line
  9. 9. Create a Django app locally $ $ $ $ $ mkdir mysite && cd mysite virtualenv venv --distribute source venv/bin/activate pip install django-toolbelt django-admin.py startproject mysite .
  10. 10. Create a Procfile Create a Procfile in your root project directory: # Procfile web: gunicorn hellodjango.wsgi
  11. 11. Create requirements.txt $ pip freeze > requirements.txt Note: If you do this out of order, you’ll need to manually create requirements.txt
  12. 12. Modify settings.py import dj_database_url DATABASES['default'] = dj_database_url.config() SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') ALLOWED_HOSTS = ['*'] # Static asset configuration import os BASE_DIR = os.path.dirname(os.path.abspath(__file__)) STATIC_ROOT = 'staticfiles' STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static'), )
  13. 13. Modify wsgi.py from django.core.wsgi import get_wsgi_application from dj_static import Cling application = Cling(get_wsgi_application())
  14. 14. Store your app in git First create a .gitignore file; add: venv *.pyc staticfiles
  15. 15. Store your app in git Initialize a new git repository $ git init Add the new files $ git add . Commit your files $ git commit -m "initial commit"
  16. 16. Push your code to Heroku Create a new app on Heroku $ heroku create Deploy your code to Heroku $ git push heroku master
  17. 17. Start your app Each Heroku app comes with 1 free dyno. Start a Heroku dyno $ heroku ps:scale web=1 Scaling dynos... done, now running web at 1:1X. Terminology: Dynos are isolated, virtualized Unix containers, that provide the environment required to run an application.
  18. 18. Visit your app $ heroku open
  19. 19. Visit your app Congrats! You’ve set up a live Djangopowered application via Heroku.

×