問題:
When I render a page using the Django template renderer, I can pass in a dictionary variable containing various values to manipulate them in the page using {{ myVar }}
.當我使用 Django 模板渲染器渲染頁面時,我可以傳入一個包含各種值的字典變量,以使用{{ myVar }}
在頁面中操作它們。
Is there a way to access the same variable in Javascript (perhaps using the DOM, I don't know how Django makes the variables accessible)?有沒有辦法在 Javascript 中訪問相同的變量(也許使用 DOM,我不知道 Django 如何使變量可訪問)? I want to be able to lookup details using an AJAX lookup based on the values contained in the variables passed in.我希望能夠根據傳入的變量中包含的值使用 AJAX 查找來查找詳細信息。
解決方案:
參考一: https://stackoom.com/question/1Fiu參考二: Django Template Variables and Javascript