[Django]-AttributeError: 'NoneType' object has no attribute 'startswith' while launching the Django App

2👍

You did not set a value for HOST in the:

# settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', 
        'NAME': 'my_db_name',
        'USER': 'my_db_user',
        'PASSWORD': 'my_password',
        'HOST': 'name_of_the_host',
        'PORT': '3306'
    }
}

If you use an environment variable, the environment variable needs to be defined, so if you use:

# settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', 
        'NAME': 'my_db_name',
        'USER': 'my_db_user',
        'PASSWORD': 'my_password',
        'HOST': os.getenv('MYSQL_HOST'),
        'PORT': '3306'
    }
}

then the MYSQL_HOST environment variable should be defined. It is is not, os.getenv will return None, hence the error.

Leave a comment