Heroku Django Library
pip install django-heroku
Gunicorn - HTTP server
pip install gunicorn
Whitenoise - serve static files directly from the web server
pip install whitenoise
Download and install the Heroku CLI
Make sure you are in the same folder as manage.py and log in to Heroku
heroku login
heroku create _your_app_name_
Create the Procfile file:
ni Procfile
Inside paste:
web: gunicorn _your_project_name_.wsgi
Imports
import django_heroku
import dj_database_url
DEBUG - set to False:
DEBUG = False
Update ALLOWED_HOSTS
ALLOWED_HOSTS = ['heroku_app_name.herokuapp.com', 'my_connected_domain', 'localhost', '127.0.0.1']
MIDDLEWARE: as the second item insert:
Databases section
At the bottom of the file add whitenoise manifest and heroku coinfiguration:
Perform all steps from the Security section
Check the Django official deployment checklist
Run django deploy check
python manage.py check --deploy
Create the requirements.txt file
pip freeze > requirements.txt
Deploy
git init
heroku git:remote -a nameofherokuapp
git add .
git commit -am "First deployment"
git push heroku master
Navigate to the Heroku homepage: APP - Overview - Heroku Postgres - Settings - View Credentials - Copy URI and write it down
settings.py: under the existing DATABASE entry, add:
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
git add .
git commit -am "Migrations"
git push heroku master
python manage.py collectstatic
git add .
git commit -m 'static'
git push heroku main
Wrong python version (Heroku docs)
python-3.10.1
Unable to publish