0
我在我的網站上有幾個產品頁面,它們將具有相同的索引和頁面設置,但具有不同的url路徑。我想重新使用該模板,但過濾結果只顯示該索引頁的子對象。爲多個列表重複使用W Index目錄模板
例如:
目前
www.../carnival - index page that displays all child objects
www.../carnival/rides-games - child page of carnival
www.../carnival/etc...
我想使用該網站的其他部分相同的索引頁:
www.../catering - index page that displays all child objects
www.../catering/fun-food - child page of catering
www.../catering/etc...
但是,當我使用相同的索引頁面並訪問我的carnival
頁面,我也看到了所有的餐飲對象。
下面是我的代碼 - 請幫助我;我知道必須有一個幹這種方式。謝謝。
standard_index_page.html
{% block content %}
...
{% standard_index_listing %}
...
{% endblock %}
standard_index_listing.html
{% if pages %}
{% for pages in pages %}
<div class="col-xs-6 col-sm-4 col-md-3 mt20 hover-float">
<div class="team-two">
{% if pages.feed_image %}
{% image pages.feed_image original as img %}
<div class="team-one" data-animation="zoomIn" data-animation-delay="100" style="background: url('{{ img.url }}') no-repeat top center; background-size: cover"></div>
{% endif %}
<h5>{{ pages.title }}</h5>
<small><a href="{% pageurl pages %}" class="color-pasific">Learn More </a></small>
</div>
</div>
{% endfor %}
{% endif %}
home_tags.py
@register.inclusion_tag(
'home/tags/standard_index_listing.html',
takes_context=True
)
def standard_index_listing(context):
pages = StandardPage.objects.live()
return {
'pages': pages.select_related('feed_image'),
'request': context['request'],
}
你也可以做'頁=背景[ '頁'] get_children()生活()'。 – 404