html 中的 django list_filter

django list_filter in html

如何将此 list_filter 导入我的 html?您有任何易于遵循和易于理解的文档吗?可能吗?

class ArticleListView(ListView):

    model = StudentsEnrollmentRecord
    s=StudentsEnrollmentRecord.objects.all()
    paginate_by = 50  # if pagination is desired
    searchable_fields = ["Student_Users", "id", "Section"]
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['now'] = timezone.now()
        return context 

您可以使用模板标签来循环您的对象并填充您的 html:

https://docs.djangoproject.com/en/3.0/ref/templates/builtins/

给你一个启动:

<ul>

{% for filter in s %}

<li>{{ filter.Student_Users }}</li>

{% endfor %}

</ul>

这基本上会为您的查询集中的每个项目创建一个 <li>。 确保通过上下文从您的视图中正确返回所需的数据:

context = {
        'queryset': s,    
    }
    return (context)