gpt4 book ai didi

python - Django 表格 : cannot call form. 干净

转载 作者:太空宇宙 更新时间:2023-11-04 09:15:30 30 4
gpt4 key购买 nike

考虑以下堆栈跟踪:

In [3]: f.clean()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
C:\Users\Marcin\Documents\oneclickcos\lib\site-packages\django\core\management\commands\shell.pyc in <module>()
----> 1 f.clean()

C:\Users\Marcin\Documents\oneclickcos\oneclickcos\mainapp\incorporate_helpers.pyc in clean(self)
569 This checks the relations between fields, ensures consistent state, and exports bits about the state of the form that can be used in subsequent
validations
570 """
--> 571 cleaned_data = super(IncorporateForm, self).clean()
572 #logger.debug('IncorporationForm.cleaned_data: ' + str(cleaned_data))

573 try:

C:\Users\Marcin\Documents\oneclickcos\oneclickcos\mainapp\incorporate_helpers.pyc in clean(self)
402
403 def clean(self):
--> 404 cleaned_data = super(CreateForm, self).clean()
405 # trying to use an empty pk can result in a ValueError. Easier to expunge.

406 if cleaned_data.get('pk', None) == '': del cleaned_data['pk']

C:\Users\Marcin\Documents\oneclickcos\lib\site-packages\django\forms\forms.pyc in clean(self)
315 association with the field named '__all__'.
316 """
--> 317 return self.cleaned_data
318
319 def has_changed(self):

AttributeError: 'IncorporateForm' object has no attribute 'cleaned_data'

(所有相关代码都显示在上面的跟踪中)。

我的代码符合 https://docs.djangoproject.com/en/1.4/ref/forms/validation/#cleaning-and-validating-fields-that-depend-on-each-other 中的示例;然而,似乎 BaseForm 返回期望 cleaned_data 存在。

在文档中我没有看到用户代码有责任在调用 clean 之前创建 cleaned_data。是什么赋予了?这是 Django 中的错误吗?

django 1.4 和 1.3.1 出现错误。

最佳答案

您根本不应该直接调用 clean。您应该调用 form.is_valid()

关于python - Django 表格 : cannot call form. 干净,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9909131/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com