Didina Deen Didina Deen - 1 year ago 89
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?

Answer Source

I imported requests:

import requests

and sent it to the template:

dictionary = {"session_cookie_age": SESSION_COOKIE_AGE}
return render(request, dictionary, "yourtemplate.html")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download