1
我有這個代碼,我使用從樹枝根據相同的日期顯示部分。解決在Django模板中設置變量
我想在Django中使用相同的代碼,但我無法在其模板系統中設置變量。做這件事的理智方式是什麼?正確的方法?人們如何解決這個問題?
{% set date = "prout" %}
{% for article in articles %}
{% if article.date != date %}
{% if date != "prout" %}
</ul>
</section>
{% endif %}
{% set date = article.date %}
<section class="row">
<h2>{{ article.date }}</h2>
<ul>
<li>+ {{ article.titre }}</li>
{% else %}
<li>+ {{ article.titre }}</li>
{% endif %}
{% endfor %}
</ul>
</section>
你應該做你的邏輯視圖中沒有模板。在django中,你也可以做{%with'prout'as date%} –
我對Django來說很新,我不知道該怎麼做。在視圖還是模型中? –
在視圖中設置的上下文 – vadimchin