I have a function in Django views.py which passes a context variable called "queues" into an HTML page. In the HTML page, I have a button where if I click it, it should pass the context variable "queues" into a JavaScript function func. However, as shown in the image attached, I see some errors with the way I am doing this. What is the correct syntax to do this? HTML code
-
Not terribly familiar with Django, but you're missing quotes around your onclick parameter, try this: onclick="func('{{queues}}')"Marcel Herd– Marcel Herd2021-09-26 22:13:36 +00:00Commented Sep 26, 2021 at 22:13
-
1Please post your code as text instead of a screenshot, as links may break, screenreaders cannot process the image etc.Ermiya Eskandary– Ermiya Eskandary2021-10-04 18:01:12 +00:00Commented Oct 4, 2021 at 18:01
Add a comment
|
1 Answer
In your template :
<script>
let queues = {{queues_declared_in_context_view}};
...
use your javascript variable queues
</script>
In addition, here is an interesting article about safety when passing data from context to templates
1 Comment
vially
The resource you shared is super useful to me...thanks a million