building a django app on heroku
DESCRIPTION
A quick overview on how to build a Django app on the Heroku platformTRANSCRIPT
![Page 1: Building a Django App on Heroku](https://reader034.vdocument.in/reader034/viewer/2022051323/54b6ba004a7959e05e8b45e1/html5/thumbnails/1.jpg)
Building a Django App on HerokuGet your project up and running in 20 minutes or less.
![Page 2: Building a Django App on Heroku](https://reader034.vdocument.in/reader034/viewer/2022051323/54b6ba004a7959e05e8b45e1/html5/thumbnails/2.jpg)
What is Heroku?● Platform-as-a-Service (PaaS)● Acquired by salesforce.com in 2010
![Page 3: Building a Django App on Heroku](https://reader034.vdocument.in/reader034/viewer/2022051323/54b6ba004a7959e05e8b45e1/html5/thumbnails/3.jpg)
Why Heroku?● Focus on developer productivity● 100% free plan includes hosting & db● No need to think about servers● Easily scales
![Page 4: Building a Django App on Heroku](https://reader034.vdocument.in/reader034/viewer/2022051323/54b6ba004a7959e05e8b45e1/html5/thumbnails/4.jpg)
Why we chose Heroku● Free to start● No bandwidth/budget for devops● Flexibility to deploy elsewhere in future if
needed
![Page 5: Building a Django App on Heroku](https://reader034.vdocument.in/reader034/viewer/2022051323/54b6ba004a7959e05e8b45e1/html5/thumbnails/5.jpg)
PrerequisitesFamiliarity with:
● command line● git
![Page 6: Building a Django App on Heroku](https://reader034.vdocument.in/reader034/viewer/2022051323/54b6ba004a7959e05e8b45e1/html5/thumbnails/6.jpg)
PrerequisitesInstall:● pip
http://www.pip-installer.org● Postgres
pip install psycopg2
http://initd.org/psycopg/
![Page 7: Building a Django App on Heroku](https://reader034.vdocument.in/reader034/viewer/2022051323/54b6ba004a7959e05e8b45e1/html5/thumbnails/7.jpg)
PrerequisitesInstall:● Virtualenv
pip install virtualenv
![Page 8: Building a Django App on Heroku](https://reader034.vdocument.in/reader034/viewer/2022051323/54b6ba004a7959e05e8b45e1/html5/thumbnails/8.jpg)
Getting Started1. Sign up for a Heroku account at Heroku.com2. Install Heroku Toolbelt: https://toolbelt.heroku.com3. Log in via command line
![Page 9: Building a Django App on Heroku](https://reader034.vdocument.in/reader034/viewer/2022051323/54b6ba004a7959e05e8b45e1/html5/thumbnails/9.jpg)
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 .
![Page 10: Building a Django App on Heroku](https://reader034.vdocument.in/reader034/viewer/2022051323/54b6ba004a7959e05e8b45e1/html5/thumbnails/10.jpg)
Create a ProcfileCreate a Procfile in your root project directory:
# Procfile
web: gunicorn hellodjango.wsgi
![Page 11: Building a Django App on Heroku](https://reader034.vdocument.in/reader034/viewer/2022051323/54b6ba004a7959e05e8b45e1/html5/thumbnails/11.jpg)
Create requirements.txt
$ pip freeze > requirements.txt
Note: If you do this out of order, you’ll need to manually create requirements.txt
![Page 12: Building a Django App on Heroku](https://reader034.vdocument.in/reader034/viewer/2022051323/54b6ba004a7959e05e8b45e1/html5/thumbnails/12.jpg)
Modify settings.pyimport dj_database_urlDATABASES['default'] = dj_database_url.config()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
ALLOWED_HOSTS = ['*']
# Static asset configurationimport osBASE_DIR = os.path.dirname(os.path.abspath(__file__))STATIC_ROOT = 'staticfiles'STATIC_URL = '/static/'
STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static'),)
![Page 13: Building a Django App on Heroku](https://reader034.vdocument.in/reader034/viewer/2022051323/54b6ba004a7959e05e8b45e1/html5/thumbnails/13.jpg)
Modify wsgi.py
from django.core.wsgi import get_wsgi_applicationfrom dj_static import Cling
application = Cling(get_wsgi_application())
![Page 14: Building a Django App on Heroku](https://reader034.vdocument.in/reader034/viewer/2022051323/54b6ba004a7959e05e8b45e1/html5/thumbnails/14.jpg)
Store your app in gitFirst create a .gitignore file; add:
venv*.pycstaticfiles
![Page 15: Building a Django App on Heroku](https://reader034.vdocument.in/reader034/viewer/2022051323/54b6ba004a7959e05e8b45e1/html5/thumbnails/15.jpg)
Store your app in gitInitialize a new git repository
$ git init
Add the new files$ git add .
Commit your files$ git commit -m "initial commit"
![Page 16: Building a Django App on Heroku](https://reader034.vdocument.in/reader034/viewer/2022051323/54b6ba004a7959e05e8b45e1/html5/thumbnails/16.jpg)
Push your code to HerokuCreate a new app on Heroku$ heroku create
Deploy your code to Heroku$ git push heroku master
![Page 17: Building a Django App on Heroku](https://reader034.vdocument.in/reader034/viewer/2022051323/54b6ba004a7959e05e8b45e1/html5/thumbnails/17.jpg)
Start your appStart 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.
Each Heroku app comes with 1 free
dyno.
![Page 18: Building a Django App on Heroku](https://reader034.vdocument.in/reader034/viewer/2022051323/54b6ba004a7959e05e8b45e1/html5/thumbnails/18.jpg)
Visit your app
$ heroku open
![Page 19: Building a Django App on Heroku](https://reader034.vdocument.in/reader034/viewer/2022051323/54b6ba004a7959e05e8b45e1/html5/thumbnails/19.jpg)
Visit your app
Congrats! You’ve set up a live Django-powered application via Heroku.