2

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

2
  • Not terribly familiar with Django, but you're missing quotes around your onclick parameter, try this: onclick="func('{{queues}}')" Commented Sep 26, 2021 at 22:13
  • 1
    Please post your code as text instead of a screenshot, as links may break, screenreaders cannot process the image etc. Commented Oct 4, 2021 at 18:01

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

The resource you shared is super useful to me...thanks a million

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.