pg_config for django_heroku
Install
django_heroku
:pip install django-heroku
Add
django_heroku
to yourrequirements.txt
orpipenv
:echo "django-heroku==0.3.1" >> requirements.txt
Add
django_heroku
to yourrequirements.txt
orpipenv
:python # settings.py import django_heroku django_heroku.settings(locals())
Install the
psycopg2-binary
package:pip install psycopg2-binary
Add
psycopg2-binary
to yourrequirements.txt
orpipenv
:echo "psycopg2-binary==2.9.1" >> requirements.txt
Install
dj-database-url
:pip install dj-database-url
Add
dj-database-url
to yourrequirements.txt
orpipenv
:echo "dj-database-url==0.5.0" >> requirements.txt
Configure your
DATABASE_URL
in the environment:bash export DATABASE_URL=your_database_url_here
Update your
DATABASES
setting insettings.py
: ```python # settings.py import dj_database_url
DATABASES = { 'default': dj_database_url.config(default=os.environ.get('DATABASE_URL')) } ```
Install the
gunicorn
package:pip install gunicorn
Add
gunicorn
to yourrequirements.txt
orpipenv
:echo "gunicorn==20.1.0" >> requirements.txt
Create a
Procfile
in your project root:web: gunicorn your_project_name.wsgi
Install the
whitenoise
package:pip install whitenoise
Add
whitenoise
to yourrequirements.txt
orpipenv
:echo "whitenoise==5.3.0" >> requirements.txt
Update your
MIDDLEWARE
setting insettings.py
:python # settings.py MIDDLEWARE = [ # ... 'whitenoise.middleware.WhiteNoiseMiddleware', # ... ]
Configure static file handling in
settings.py
:python # settings.py STATIC_URL = '/static/' STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
Set the
DISABLE_COLLECTSTATIC
environment variable:bash export DISABLE_COLLECTSTATIC=1
Add
python-decouple
to yourrequirements.txt
orpipenv
:echo "python-decouple==3.5" >> requirements.txt
Configure your static files and media settings using
python-decouple
insettings.py
: ```python # settings.py from decouple import config, CsvDEBUG = config('DEBUG', default=False, cast=bool) ```
Install
whitenoise
for handling static files:pip install whitenoise
Add
whitenoise
to yourrequirements.txt
orpipenv
:echo "whitenoise==5.3.0" >> requirements.txt
Update your
MIDDLEWARE
setting insettings.py
to includewhitenoise
:python # settings.py MIDDLEWARE = [ # ... 'whitenoise.middleware.WhiteNoiseMiddleware', # ... ]
Configure static file handling in
settings.py
:python # settings.py STATIC_URL = '/static/' STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
Set the
DISABLE_COLLECTSTATIC
environment variable:bash export DISABLE_COLLECTSTATIC=1