django connect to a db on heroku

  1. Install the required library: pip install dj-database-url
  2. Import the library: import dj_database_url
  3. 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)
  4. Set the DATABASE_URL environment variable in Heroku: heroku config:set DATABASE_URL=your_database_url