【发布时间】:2021-10-03 01:36:27
【问题描述】:
我正在尝试使用 django 查询集显示名称列表,这是我的代码
def vfunc(request):
context={}
bats = Bat.objects.all().order_by('-id')
context['bats'] = bats
[each.batname for each in bats] # Gives all the batnames.
return render(request, 'bat.html', context)
我想在模板上显示蝙蝠名称
$(function() {
//This works when I hardcode the values
var batData = [{
"bat":"batname1", //hardcoded & displayed in 1st row
}, {
"bat":"batname2", //hardcoded & displayed in 2nd row
}];
$("#CleanDatasNames").dxDataGrid({
dataSource: batData,
...
...
}
我尝试过类似 var batData = [{"bat":"{{bats|join:', ' }}"] 但它在同一行显示 obj1,obj2,我也尝试循环但失败了,任何帮助将不胜感激。
【问题讨论】:
标签: javascript python jquery django django-templates