我在模板中使用includes,但只想通过模板发送django queryset的一个拼接。我不想在我的视图中拼接,因为这是一个更大的for循环的一部分,它将不断地用不同的子部分调用include。这是我的一厢情愿:
{% for g in gl %} {% include 'includes/file.html' with ps=ps|id:g.id %} {% endfor %}
您应该创建一个filter标记,它将接收您的queryset并返回一个filtered标记。。。。您可以在此处找到详细信息:
https://docs.djangoproject.com/en/2.1/howto/custom-template-tags/