[Django]-Why is dj-database-url throwing me an error of : a bytes-like object is required, not 'str' and how do i get around this?

3👍

I’m not sure exactly where the problem lies in dj_database_url but reading through their github issues I think it’s a problem with some characters contained in the DATABASE_URL environment variable.

In your settings.py try using this instead of dj_database_url.parse():

... other config settings ...
DATABASE_URL = os.getenv('DATABASE_URL')
DATABASES = {
    'default': dj_database_url.config(),
}

config() should automatically use the DATABASE_URL setting by default, so simply setting it from your environment variable first and then calling config() after should bypass whatever problem the parse() method in handling the url.

👤pspahn

Leave a comment