有人可以帮忙吗?
我想从数据库中打印一些计数(总记录中,完整字段= true,而另一个则为false。
下面我做错了什么?
谢谢
观看次数
function myFunction() {
var i, dicepic;
var itotal = ktotal = ltotal = jtotal = totalgeral = 0;
var dice = Math.floor(Math.random() * 1000) + 1;
for (i = 0; i < dice; i++) {
itotal++;
totalgeral++;
var k;
for (k = 1; k < 7; k++) {
ktotal++;
totalgeral++;
document.getElementById("first-picture" + k).src = 'images/empire.jpg';
}
var l;
for (l = 1; l < 7; l++) {
ltotal++;
totalgeral++;
document.getElementById("first-picture" + l).src = 'images/black.jpg';
}
var j;
for (j = 1; j < 7; j++) {
jtotal++;
totalgeral++;
var dicepic = Math.floor(Math.random() * 11) + 1;
document.getElementById("first-picture" + j).src = 'images/image' + dicepic + '.jpg';
document.getElementById("vari1").innerHTML = "Value of i is: " + i;
document.getElementById("vari2").innerHTML = "Value of Dice is: " + dice;
document.getElementById("pic-code-" + j).innerHTML = "Code is: " + dicepic;
}
}
document.getElementById("vari3").innerHTML = "Value of Dice is: " + dice;
document.getElementById("loop-i").innerHTML = "Loop I: " + itotal;
document.getElementById("loop-k").innerHTML = "Loop K: " + ktotal;
document.getElementById("loop-l").innerHTML = "Loop L: " + ltotal;
document.getElementById("loop-j").innerHTML = "Loop J: " + jtotal;
document.getElementById("loops-total").innerHTML = "Total: " + totalgeral;
}
URLS
def task_count(request):
completetasks = Todo.objects.filter(complete=True).count()
incompletetasks = Todo.objects.filter(complete=False).count()
return render(request, 'counts.html')
COUNTS.HTML
urlpatterns = [
url(r'^$', views.todo, name='index'),
url(r'^create/$', views.create_task, name='create'),
url(r'^counts/$', views.task_count, name='counts'),
答案 0 :(得分:1)
在您的视图文件中这样更改
def task_count(request):
completetasks = Todo.objects.filter(complete=True).count()
incompletetasks = Todo.objects.filter(complete=False).count()
context = {
'completetasks': completetasks,
'incompletetasks': incompletetasks
}
return render(request, 'counts.html', context)
然后在counts.html
{{ completetasks }}
{{ incompletetasks }}