Skip to content

Instantly share code, notes, and snippets.

@CleverProgrammer
Last active July 28, 2019 05:19
Show Gist options
  • Save CleverProgrammer/1344d65e4bce640d2e17096c4390f7a4 to your computer and use it in GitHub Desktop.
Save CleverProgrammer/1344d65e4bce640d2e17096c4390f7a4 to your computer and use it in GitHub Desktop.
How to Host a Django App on Heroku
pip install gunicorn
pip install django-heroku
pip freeze > requirements.txt
# login to your heroku
heroku login
# create new app if one doesn't yet exist
heroku create
# create a new postgres database for your app
heroku addons:create heroku-postgresql:hobby-dev
# migrate your database to the heroku app
heroku run python manage.py migrate
# before you do this, make sure to add your SECRET_KEY to your env variables in your heroku app settings
git add .
git commit -m "Ready to heroku this sucker in the face."
git push heroku master
web: gunicorn project_name.wsgi
import django_heroku
# All the way at the bottom of the file
# ...
django_heroku.settings(locals())
@sojay
Copy link

sojay commented Nov 2, 2018

I understand that by default, a Heroku app is available at its Heroku domain, which has the form [name of app].herokuapp.com

How about pointing the app to a custom domain?

@AhmadAyyaz1993
Copy link

migrate your database to the heroku app

heroku run python manage.py migrate

migrations should be the last step as it wont find manage.py file before pushing it to git

@agusalex
Copy link

Nice gist, however, I found some issues, first one is that Heroku throws an error when running
heroku addons:create heroku-postgresql:hobby-dev
What I found is that it is not needed as Heroku by itself creates a Postgres DB when pushing the project.
Also I find it odd that you make migrations before you commit and push your code. Before you commit and push there is no manage.py file on Heroku's dynos.
Doing that first and then migrating is what worked for me.

@abu-yusuf-dev
Copy link

Updated:

pip install gunicorn
pip install django-heroku
pip freeze > requirements.txt

-> login to your heroku
heroku login

-> initiate git
git init

-> create new app if one doesn't yet exist
heroku create appname

-> create a new postgres database for your app
heroku addons:create heroku-postgresql:hobby-dev

-> before you do this, make sure to add your SECRET_KEY to your env variables in your heroku app settings
git add .
git commit -m "Ready to heroku this sucker in the face."
git push heroku master

-> migrate your database to the heroku app
heroku run python manage.py migrate --app appname

I did deploy a bunch of projects on heroku. I think this is the real approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment