1
如果有人沒有在我的Django formset中填寫任何表單,則返回[{}]
。用空字典創建一個返回False的Python
如何測試集合中的此字典是否已填充?像下面,雖然這並不能爲空字典工作似乎使列表返回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"