django connect to a db on heroku
- Install the required library:
pip install dj-database-url
- Import the library:
import dj_database_url
- Update the database settings in settings.py:
python import dj_database_url db_from_env = dj_database_url.config(conn_max_age=600) DATABASES['default'].update(db_from_env)
- Set the
DATABASE_URL
environment variable in Heroku:heroku config:set DATABASE_URL=your_database_url