Django模板 - 停止处理模板(Django Template - Stop processing template)
我正在寻找方式来清理django中的模板。 一个简单的解决方案是将其分解成多个模板,但我们不想这样做。
我们基本上有以下几点
{%if data.some_state %} Display some markup {% else %} {%if data.some_state_2 %} State 2 different html view {% else %} {%if data.process_data %} Display some list of data {% else %} No Data to display! {% endif %} <!-- if data.process_data--> {% endif %} <!-- if data.some_state_2 --> {% endif %} <!-- if data.some_state -->
所以这是非常混乱和难以阅读。 如果我可以在“功能”中做到这一点,我会使用if / else if或returns。
模板语言中是否有一种方法可以执行类似的操作(stop_processing_template将告诉模板我们已完成...):
{%if data.some_state %} Display some markup {% endif %} {% django_stop_processing_template %} {%if data.some_state_2 %} State 2 different view {% endif %} {% django_stop_processing_template %} {%if data.process_data %} Display some list of data {% endif %} {% django_stop_processing_template %} No data provided !
I am looking for way to clean up a template in django. A simple solution would be to break this up into multiple templates, but we do not want to do that.
We basically have the following
{%if data.some_state %} Display some markup {% else %} {%if data.some_state_2 %} State 2 different html view {% else %} {%if data.process_data %} Display some list of data {% else %} No Data to display! {% endif %} <!-- if data.process_data--> {% endif %} <!-- if data.some_state_2 --> {% endif %} <!-- if data.some_state -->
So that is extremely confusing and hard to read. If I could do this in a "function" i would use if/else if or returns.
Is there a way in template language to do something like (stop_processing_template would tell the template we are done... ):
{%if data.some_state %} Display some markup {% endif %} {% django_stop_processing_template %} {%if data.some_state_2 %} State 2 different view {% endif %} {% django_stop_processing_template %} {%if data.process_data %} Display some list of data {% endif %} {% django_stop_processing_template %} No data provided !
原文:https://stackoverflow.com/questions/8448405