score:0
the question needs more context to help us understand your goal. it seems you are mixing python with javascript data structures.
my general recommendation is that you first prepare the python data structure to what you will need and then convert it to json. looping within django template language should be used only on simple cases.
if you use django>=2.1 you can use json-script
template tag
{{ data|json_script:"my-data" }}
https://docs.djangoproject.com/en/2.1/ref/templates/builtins/#json-script
if not, you can use
# views.py
import json
def foo(request):
databf = {"a": [{"c": [1,2,3,1,1]},{"d": [1,2,3,1,1]}]}
# here you can manipulate the data accordingly to what you need
data = json.dumps(databf)
return render(request, "index.html", context={"data": data})
on the template side
<script>
const datajs = {{ data | safe }};
</script>
the datajs is a javascript object that you can work with.
i've made an example that you can check https://repl.it/@ivanpereira/python-to-javascript-django-template
score:0
you can do this in 2 ways.
store all values in a list, which javascript will consider as json array, and loop over using javascript itself. this way you won't be able to update records from server and all values that has to be looped over should be pre-fetched.
you can use ajax call to pass the selected index from javascript and return the new array and update that in the template using javascript itself.
Source: stackoverflow.com
Related Query
- Can I use a variable as index in for loop in python?
- How can i loop some specific key in each index json data and put it in dataset: data ? (chart.js)
- TS how can I use a class variable inside method?
- Can I use chartJS for drawing a stock map with rectangle?
- how I can get label name when user click on particular area in doughnut chart.js? I am not able to find the index of selected area for chart.js
- how can i use inline plugin inner title for chart js?
- Cannot access a variable declared outside a For loop (Javascript)
- How can I make my chart's axes use the same proportions for scaling?
- how do I use for loop inside script tag in ejs
- Use Google Spreadsheet as data source for Chart.js
- How to use variable for data in Charts.js Pie Chart?
- How can labels/legends be added for all chart types in chart.js (chartjs.org)?
- Chart JS - Use time for xAxes
- Can I specify a different font size for each row of text in Chart Title?
- How to use 'time' (data from database, data type: timestamp ) for plotting graph in Chart JS
- Can I use a gradient in Chart.js without accessing the chart context when the chart is created?
- Iterate over query for use in Charts.js using Coldfusion
- Can JS lib can be use in Native Tizen App?
- Display multiple chart.js charts using for loop in Django template
- How can I create custom tooltips for each data point in a graph?
- Chart is too big. How can I reduce size for the chart in vue js?
- How to use chartjs-plugin-datalabels for specific charts using vue-chart.js
- Is there any way to use 2 different color for the same bar in a chart?
- How to create a variable for chart js datalabel plugin formatter
- how can i send a list of numbers from views.py to a chartjs file im using for the front?
- How do I use this new extension for chart.js?
- How to use async data for use with chart.js in ionic
- How can I set the yAxis scale for the chart?
- How to use set the color for each bar in a bar chart using chartjs?
- My for loop does not iterate in Javascript
More Query from same tag
- Populate chart.js from data table / SQL result set
- Setting dynamic state data in Chart.JS + React
- HTML minification via Gulp.js is breaking my Chart.js chart in my Angular app
- Chart.js v3 Fade Animation in delay
- Dotted Line in ChartJS
- How do I display chart on my HTML page based on JSON data sent by Node JS
- Legends for line charts in Chart.js
- ChartJS: Position labels at end of doughnut segment
- Should I remove the leading "0" when sending PHP array to JSON?
- Update Chart using react
- Export chart.js into fixed sized chart
- create a multi line chart using Chart.js
- My chart.js canvas disappears after hide() function
- How to add text inside the doughnut chart using Chart.js version 3.2.1
- vue-chartjs how to load data
- vb.net string to chartjs data field?
- How to properly render Chartjs with big difference between bars data?
- Chart.js not showing legends
- Angular Chart.js Bar Chart
- How to display grouped bar chart using chart.js?
- Unable to display data via Charts.JS
- Is it possible to use mouseenter and mouseleave event in chart js?
- Chart.js add icon at the top of bar
- Change font size and font color in Chartjs Angular 5
- Legend position is not vertically in middle in Donut chart
- Chart.Js pie chart click
- Plot a multi-line graph from grouped JSON object using Charts.js
- Chart JS Show HTML in Tooltip
- Remove tooltip if has no label
- Chart.js wrong x axis date time?