DEBUG = bool( os.environ.get('DJANGO_DEBUG', True))
import os
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'YOUR_SECRET_KEY')
npm install -g heroku
web: gunicorn [YOUR_APP_NAME].wsgi --log-file -
- same directory as
manage.py
The Gunicorn "Green Unicorn" is a Python Web Server Gateway Interface HTTP server.
pip install gunicorn
dj-database-url (Django database configuration from environment variable)
pip install dj-database-url
Add it into the bottom of the
settings.py
# Heroku: Update database configuration from $DATABASE_URL.
import dj_database_url
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)
psycopg2 (Python Postgres database support)
pip install psycopg2-binary
Install
whitenoise
pip install whitenoise
Add it into the MIDDLEWEAR of the
settings.py
MIDDLEWARE = [
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
Add it into the bottom of the
settings.py
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
The Python requirements of your web application must be stored in a file requirements.txt in the root of your repository
pip freeze > requirements.txt
runtime.txt
tells Heroku which programming language to use
python-3.6.9
heroku create [APP_NAME]
git add .
git commit
git push heroku master
heroku run python manage.py migrate
heroku run python manage.py createsuperuser
heroku open
+
heroku config:set DISABLE_COLLECTSTATIC=1
To export the data from your Heroku Postgres database, create a new backup and download it.
heroku pg:backups:capture
heroku pg:backups:download
$ heroku maintenance:on
Enabling maintenance mode for myapp... done
$ heroku maintenance:off
Disabling maintenance mode for myapp... done
$ heroku maintenance
off
heroku restart
- run this when you see this message
- "Your account has reached its concurrent builds limit"
heroku run python manage.py loaddata [YOUR_JSON_FILE_NAME]