It is going to be like following.
In HTML (doesn't have to be div of course any HTML tag can get data
attribute:
...
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:
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
Hi Cutest,
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
As you can guess this is general problem for all backend languages for
passing data to JS.
AFAIK the standard practice is attaching the value to a DOM element as
"data" property and using fetching the value from that element in your JS.
If it is a primitive value it is easy to do so, if it is
Hi Steve,
I am new to Django as well. To do what you wanted to do (pass values from
python to js), I used ajax queries (using jquery) and then did a
JsonResponse to the ajax call. The ajax call then handles the data as
required.
Sample usage:
VIEWS.PY:
class InstructorDeleteView(DeleteView):
I am trying to pass values from Django/Python to Javascript, and have it
working to a degree, but need some assistance (obligatory: I'm new to
Django so could be hosing this)
I have three files in play here, *views.py, app.js, home.html*. I can get
the values passed to home.html as part of the
6 matches
Mail list logo