我做了这张桌子,但我不知道怎么编号。我想要一个前10名的名单,我从数据库里得到所有的数据。我基本上想让它显示“1”和下一个“2”和下一个“3”等等。我怎样才能做到这一点?你知道吗
def home(请求): 斯特拉特数据=data.objects.all所有()[:10]
count = data.objects.count()
numbers = []
for dataCount in range(1, count + 1):
numbers.append(dataCount)
context = {
'data': straatData,
'count': numbers,
}
return render(request, 'home.html', context)
我需要把最上面的数字显示为1,2,3,4。。。和结果一样多。但我不知道怎么做
不需要为此设置上下文变量。您可以在模板代码中使用
forloop.counter
。你知道吗如果要从0开始计数,请使用
forloop.counter0
也许您应该使用jinja在循环中呈现表?你知道吗
在html中:
如果看不到html,就很难知道当前如何呈现表。你知道吗
相关问题 更多 >
编程相关推荐