March 2020
Intermediate to advanced
608 pages
17h 17m
English
Follow these steps to create and include the JavaScript settings:
# myproject/apps/core/views.pyimport jsonfrom django.http import HttpResponsefrom django.template import Template, Contextfrom django.views.decorators.cache import cache_pagefrom django.conf import settingsJS_SETTINGS_TEMPLATE = """window.settings = JSON.parse('{{ json_data|escapejs }}');"""@cache_page(60 * 15)def js_settings(request): data = { "MEDIA_URL": settings.MEDIA_URL, "STATIC_URL": settings.STATIC_URL, "DEBUG": settings.DEBUG, "LANGUAGES": settings.LANGUAGES, "DEFAULT_LANGUAGE_CODE": settings.LANGUAGE_CODE, ...