Deploying a Django project on Heroku

1. Modify settings.py

1-1. Debug

DEBUG = bool( os.environ.get('DJANGO_DEBUG', True))

1-2. SECRET_KEY

import os
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'YOUR_SECRET_KEY')

2. Install Heroku

npm install -g heroku

3. Update the app for Heroku

3-1. Procfile

web: gunicorn [YOUR_APP_NAME].wsgi --log-file -
  • same directory as manage.py

3-2. Install Gunicorn

The Gunicorn "Green Unicorn" is a Python Web Server Gateway Interface HTTP server.

3-3. Database configuration

dj-database-url (Django database configuration from environment variable)

Add it into the bottom of the settings.py

psycopg2 (Python Postgres database support)

3-4. Serving static files in production

Install whitenoise

Add it into the MIDDLEWARE of the settings.py

Add it into the bottom of the settings.py

3-5. Requirements

The Python requirements of your web application must be stored in a file requirements.txt in the root of your repository

3-6. Runtime

runtime.txt tells Heroku which programming language to use

4. Create and upload the website

4-1. Create the app

4-2. Push our app to the Heroku repository

4-3. Set up the database tables

4-4. Create superuser

4-5. Open your app

5. You are now live

+

Heroku Tips & Tricks

1. Disable collectstatic

To export the data from your Heroku Postgres database, create a new backup and download it.

3. Maintenance Mode

To enable maintenance mode

To disable maintenance mode

To check the current maintenance status of an app

4. Restart

  • run this when you see this message

    • "Your account has reached its concurrent builds limit"

5. Loaddata

Last updated