有就可以解决这个两种方式。
第一种是按类型来过滤你的子页面在您看来,如:
page = Page.objects.get(slug='current-page')
pages_with_images = Page.objects.filter(parent=page, type='image')
pages_with_testimonials = Page.objects.filter(parent=page, type='testimonial')
然后,在你的模板,可以分别通过pages_with_images
和pages_with_testimonials
迭代:
{% for subpage in pages_with_images %}
...
{% endfor %}
{% for subpage in pages_with_testimonials %}
...
{% endfor %}
第二解决方法是检查模板中子页的类型:
{% for subpage in self.get_children %}
{% if subpage.type == 'image' %}
...
{% endif %}
{% endfor %}
谢谢这个工程,看起来不错:-)! –