Я пытаюсь найти способ скрыть мой ключ карты Google, отображаемый в скрипте javascript.
Ключ генерируется из настроек django.
Я не уверен, как правильно добитьсяэто с javascript script and src
settings.py
GOOGLE_MAP = "XZZZZZZX"
views.py
def foo_list(request):
"""
Render list of foo.
"""
foo = Foo.objects.all()
# Google Map Key
google_map_key = settings.GOOGLE_MAP
context = {
'foo': foo,
'google_map_key': google_map_key
}
return render(request, 'snippet/index.html', context)
HTML
{% extends "base.html" %}
{% load static %}
{% block content %}
<!-- Render Map on HTML -->
<div id="map"></div></br></br>
<!-- Pass the Google Map key variable to Front end -->
<div id="google_map" style="display:none" value="{{ google_map_key }}"></br>
{% endblock %}
{% block key %}
<!-- Grab the Google Map key value from HTML above -->
var name_ = document.getElementById('google_name').getAttribute("value");
<!-- Google Map Key -->
<script id="name" data-name="value" src="https://maps.googleapis.com/maps/api/js?key=XZZZZZZX&callback=initMap" async defer></script>
{% endblock %}
Как я могу заменитьключ карты Google с пользовательской переменной из бэкэнда?