简体   繁体   English

如何将变量从settings.py(python)发送到javascript(js)

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

I need to get a variable from the settings in python: 我需要从python中的设置获取变量:

SESSION_COOKIE_AGE = 4500

And use it in a javascript (js). 并在javascript(js)中使用它。

I found this: https://chriskief.com/2013/09/19/access-django-constants-from-settings-py-in-a-template/ 我发现了这个: 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")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM