【发布时间】:2014-03-14 06:50:00
【问题描述】:
如果有人没有在我的 Django 表单集中填写任何表单,它会返回 [{}]。
如何测试集合中的这本字典是否已被填充?类似于以下内容,尽管这不起作用,因为空字典似乎使列表返回 True:
form_output_when_empty = [{}]
if form_output_when_empty:
print "This should not print"
# currently this prints out, which is not what I want!
else:
print "This should print."
form_output_when_filled = [{'name': 'John'}]
if form_output_when_filled:
print "This should print"
else:
print "This should not print"
【问题讨论】:
标签: python django dictionary