【发布时间】:2019-07-11 00:59:02
【问题描述】:
我正在使用 django-filter 来输出我的模型的过滤结果。那里没有问题。 下一步是添加分页器.. 虽然现在挣扎了好几天。
views.py:
def funds_overview(request):
f = FundFilter(request.GET, queryset=Fund.objects.all()).qs
paginator = Paginator(f, 5)
page = request.GET.get('page')
funds = paginator.get_page(page)
return render(request, 'funds/funds.html', {'filter': funds})
funds.html:
<form method="get">
<div class="well">
<h4 style="margin-top: 0">Search Criteria</h4>
<div class="row">
<div class="form-group col-sm-4 col-md-3">
{{ filter.form.fund_name.label_tag }}
{% render_field filter.form.fund_name class="form-control" %}
</div>
</div>
<button type="submit" class="btn btn-primary">
<span class="glyphicon glyphicon-search"></span> Search
</button>
{% for fund in filter.qs %}
<p>{{fund.name}} </p>
{% empty %}
No funds match your search criteria
{% endfor %}
浏览器中的结果 “没有资金符合您的搜索条件”行 ..
谁能帮忙?我认为两次调用 GET 请求有问题?
谢谢!
【问题讨论】:
-
我已经发布了一个答案,显示您的模板中的页面使用存在问题,它有帮助吗?
标签: django pagination django-filter django-pagination