对于给定的对象,我有三个条件,1。要启动,2。开始,和3。已完成。
我过滤视图中的对象,并向模板发送三个变量-
tostart_objects
、started_objects
和{
现在,我在html模板中循环三个for循环,如下所示:
{% 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 %}
我可以不把相同的代码块放在三个不同的地方重用吗? 如何做到这一点?请告诉我,谢谢!在
一种方法是将HTML块放在一个单独的模板文件中,并使用
{% include %}
将其包含在每个循环中。在此基础上,可以将整个循环定义为以对象列表为参数的包含模板标记。在或者,可以将视图中的三个列表串联起来,然后循环查看结果。在
相关问题 更多 >
编程相关推荐