It is going to be like following.

In HTML (doesn't have to be div of course any HTML tag can get data 
attribute:
<div id="backend-to-js-name" data-name="{{form.name}}">...</div>

Then in JS:
var dataElement = document.getElementById('backend-to-js-name');
var name = dataElement.dataset.name;
console.log(name);

Check it out "data" attributes 
here: 
https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes

On Thursday, May 24, 2018 at 6:44:39 AM UTC-7, Akshay Gaur wrote:
>
> Hi Cuneyt,
> How do you add the data fields and their values to tags generated by 
> python? For example, how would you add a data field to something generated 
> by {{ form.name }}?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/642d449e-4241-4c63-9330-f392396196a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to