1
重用HTML塊不同的for循環,我有三個條件給定對象,1.開始,2.開始和3.完成。 我過濾視圖中的對象本身並將三個變量發送到模板 - tostart_objects
,started_objects
和finished_objects
。Django的在同一個模板
我現在循環如下:
{% for obj in tostart_objects %}
// chunk of html template to display all the object
{% endfor %}
{% for obj in started_objects %}
// similar chunk of html template as above
{% endfor %}
{% for obj in finished_objects %}
// similar chunk of html template as above
{% endfor %}
而不是把相同的代碼塊的,我不能在三個不同的地方重複使用它們? 這怎麼辦?請讓我知道,謝謝!
+1 [模板標籤](https://docs.djangoproject.com/zh/dev/howto/custom-template-tags/#simple-tags)文檔參考 – 2013-05-02 08:59:15
這當然是一種解決方法,但仍然存在是Django模板系統中缺少的一項功能。如果我只使用它在一個單一的模板,爲什麼有另一個文件依賴?爲什麼我無法一次看到所有代碼,最好是在第一次使用的位置? – 2014-01-15 06:27:10