Django-数据库记录读取速度太慢

时间:2019-03-25 13:42:05

标签: python django performance django-templates

我有一个数据库,其中有大约1500条关于一个课程的记录。我也在使用jQuery Datatables列出记录。

views.py:

records = Animal.objects.all()
return render(request, 'animals.html', {'records': records})

模板:

{% for record in records%}
<tr>
    <td>{{ record.id }}</td>
    <td>{{ record.specie }}</td>
    <td>{{ record.category}}</td>
    <td>{{ record.quantity }}</td>
</tr>
{% endfor %}

但是,它非常非常慢。即使将记录数减少到100,也需要大约20〜45秒才能完全加载页面。进行相同的选择即可直接在数据库上找到所有1500条记录,只需1秒。

当我使用jQuery DataTables进行分页和搜索值时,是否有办法改善加载表的时间?

编辑:

我使用了django调试工具栏,得到了以下结果: I used the django debug toolbar and I got these results

0 个答案:

没有答案