使用Django-hays统计模板中的搜索对象总数

2024-04-26 04:49:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用django haystack和xapian作为后端搜索引擎。我正在使用FacetedSearchViewFacetedSearchForm在搜索过程中切面。我已将searchqueryset传递到urls.py文件中的FacetSearchView

但问题是我无法访问模板中的searchqueryset。我只想计算找到的searchqueryset中的对象数。

在shell中,我可以使用SearchQuerySet().filter(content="foo").count()来实现它,我如何在模板中类似地做到这一点?请引导。我想要与搜索匹配的对象总数。


Tags: 文件对象djangopy模板过程shellurls
3条回答

如果要显示结果范围而不是页码,例如1001的结果21-40

Results {{ page.start_index }} - {{ page.end_index }} of {{ page.paginator.count }}

Haystack使用标准的django分页:https://docs.djangoproject.com/en/dev/topics/pagination/

{{ page.number }}页上显示{{ page.object_list|length }}{{ page.paginator.count }}结果

{{ page.object_list | length }}

相关问题 更多 >