Didina Deen Didina Deen - 5 months ago 28
Javascript Question

How to send a variable from settings.py (python) to a javascript (js)

I need to get a variable from the settings in python:


And use it in a javascript (js).

I found this: https://chriskief.com/2013/09/19/access-django-constants-from-settings-py-in-a-template/

But, is it the only way?


I imported requests:

import requests

and sent it to the template:

dictionary = {"session_cookie_age": SESSION_COOKIE_AGE}
return render(request, dictionary, "yourtemplate.html")