我知道这是一个迟到的答案,但这不是一个错误,没有什么可担心的。查看条件函数的调用堆栈,您会在wizards/views.py 中找到调用:callable(condition)
当然condition = condition(self)
两者都调用了该函数。对于前者,wizard.storage.current_step
将是None
。这是 Django 1.6 的源代码:
def get_form_list(self):
"""
This method returns a form_list based on the initial form list but
checks if there is a condition method/value in the condition_list.
If an entry exists in the condition list, it will call/read the value
and respect the result. (True means add the form, False means ignore
the form)
The form_list is always generated on the fly because condition methods
could use data from other (maybe previous forms).
"""
form_list = SortedDict()
for form_key, form_class in six.iteritems(self.form_list):
# try to fetch the value from condition list, by default, the form
# gets passed to the new list.
condition = self.condition_dict.get(form_key, True)
if callable(condition):
# call the value if needed, passes the current instance.
condition = condition(self)
if condition:
form_list[form_key] = form_class
return form_list