2014-11-21 113 views
1

我在模板中呈现表单集。如何编写一个条件,使页面显示句子“Nothing to show”,如果formset没有元素?检测模板中的空表单

下不起作用:

{% if formset %} 
    {{ formset }} 
{% else %} 
    <p>Nothing to show</p> 
{% endif %} 

回答

5

我只是找到了答案由我自己......它的工作原理与formset.forms

{% if formset.forms %} 
    {{ formset }} 
{% else %} 
    <p>Nothing to show</p> 
{% endif %}