Go through the following steps:
- Register for the Google Maps API key. You can learn how and where to do this at the Google developers' documentation at https://developers.google.com/maps/documentation/javascript/get-api-key.
- Add the Google Maps API key to the secrets and then read it out in the settings:
# myproject/settings/_base.py# …GOOGLE_MAPS_API_KEY = get_secret("GOOGLE_MAPS_API_KEY")
- At the core app, create a context processor to expose GOOGLE_MAPS_API_KEY to the templates:
# myproject/apps/core/context_processors.pyfrom django.conf import settingsdef google_maps(request): return { "GOOGLE_MAPS_API_KEY": settings.GOOGLE_MAPS_API_KEY, }
- Refer to this context processor in the template settings:
# myproject/settings/_base.py ...