Skip to content

Instantly share code, notes, and snippets.

@agusalex
Last active January 12, 2021 17:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save agusalex/70146cb09381c0adc4b3a2f68d035cfa to your computer and use it in GitHub Desktop.
Save agusalex/70146cb09381c0adc4b3a2f68d035cfa to your computer and use it in GitHub Desktop.
Setup Django with venv and Heroku Hosting

Setup Django with venv and Heroku Hosting

Setting up venv

sudo apt-get install python3-venv

python3 -m venv venv

source venv/bin/activate

python3 -m pip install --upgrade pip

pip install -r requirements.txt

python manage.py migrate

python manage.py runserver

Hosting on Heroku

1. Procfile

web: gunicorn project_name.wsgi

2. Do this in your app/settings.py

app/settings.py

import django_heroku

# Then all the way at the bottom of the file
# ...

django_heroku.settings(locals())

3. Install dependencies

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

pkg-resources conflicted for me with Heroku so remove it

4. Create Heroku App

sudo snap install heroku
heroku login
heroku create heroku_project_name

5. Commit Changes

git add .
git commit -m "hosted on Heroku"
git push heroku master

6. Migrate Django

heroku run python manage.py migrate

If you need to set up your Heroku remote on another machine

heroku git:remote -a heroku_project_name

References

I used this Medium article for the Heroku part with slight changes

@bymayanksingh
Copy link

Thanks for this !

@agusalex
Copy link
Author

No probs! happy to help :-)

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