How to use dj-database-url while connecting with postgresql in heroku using python

前端 未结 2 1416
不思量自难忘°
不思量自难忘° 2021-02-04 21:23

I\'m here because I\'m really really new with heroku-python-django-postgresql group. I have googled for a usage for dj-database-url and I don\'t understand why i have to use it

2条回答
  •  梦如初夏
    2021-02-04 22:07

    Use pip module dj-dtabase-url. Add an environmental var with the name 'DATABASE_URL' and the value from the heroku db settings.

    Important, to avoid the error 'NameError: name 'DATABASES' is not defined.' You still have to leave for example the default DATABSE settings.

    The complete code:

    import dj_database_url
    
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': 'mydatabase',
        }
    }
    DATABASES['default'] = dj_database_url.config()
    

提交回复
热议问题