Didina Deen Didina Deen - 22 days ago 8
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:

SESSION_COOKIE_AGE = 4500


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?

Answer

I imported requests:

import requests

and sent it to the template:

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