Getting ‘Settings’ object has no attribute ‘API_KEY’ as an error when trying to use API_KEY = os.environ[‘API_KEY’] in my settings file and then reference it like this: google_maps_key = settings.GOOGLE_MAPS_API_KEY in my code. Works fine in my heroku app, does anyone know how to fix? I’m using a custom settings file and I’ve ensured DJANGO_SETTINGS_MODULE env varible is set to the correct file.
I’m sure it’s loaded the settings file correctly as there was an unassigned variable error when building it located in the file that I’ve since changed but it just seems to not be able to get attributes on the settings object.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Enter your email to get $200 in credit for your first 60 days with DigitalOcean.
New accounts only. By submitting your email you agree to our Privacy Policy.
Hi there,
There are several factors to consider when diagnosing this issue with your Django app deployed on DigitalOcean’s App Platform. Here are a few things that I could suggest checking:
Environment Variables:
API_KEY
is correctly set in your DigitalOcean’s App Platform deployment environment.API_KEY
is present.DJANGO_SETTINGS_MODULE
Environment Variable:DJANGO_SETTINGS_MODULE
is correctly set. Remember, if your settings file is located atmyproject/mysettings.py
,DJANGO_SETTINGS_MODULE
should be set tomyproject.mysettings
.Check Settings File:
API_KEY
, make sure you’re not referencing it asGOOGLE_MAPS_API_KEY
or vice-versa.Error Location:
settings.GOOGLE_MAPS_API_KEY
. IfAPI_KEY
is the name in your settings file, then you should be accessingsettings.API_KEY
in your code. Verify you are accessing the correct variable name.Settings File Loading:
Local Testing:
API_KEY
andDJANGO_SETTINGS_MODULE
to mimic the production environment, and see if you can reproduce the error.Caching and Deployment:
Let me knwo how it goes!
Bobby