Passing data to Javascript: support for data attributes #479
Closed
mikko-ahonen
started this conversation in
Ideas
Replies: 1 comment
-
Aha, this is a duplicate |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In my understanding, the best practices of safely passing data from python to Javascript are described here:
https://adamj.eu/tech/2022/10/06/how-to-safely-pass-data-to-javascript-in-a-django-template/
Expecially the data attributes. For example,
<script src="{% static 'index.js' %}" defer data-follower-count="{{ follower_count }}"></script>index.js:
const data = document.currentScript.dataset;
const followerCount = parseInt(data.followerCount, 10);
Should django componnts support adding these? Currently the script tag is rendered by django components, I believe.
Beta Was this translation helpful? Give feedback.
All reactions