我有一个简单的ModelForm:
class MyForm(ModelForm):
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
del self.fields['name']
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我尝试从表单的字段列表中删除一个字段(该字段明确存在于模型中),但我得到一个例外:
TemplateSyntaxError at [..]
Caught an exception while rendering: "Key 'name' not found in Form"
Run Code Online (Sandbox Code Playgroud)
我没有写自定义表单,因此发生错误的模板是:
/templates/admin/includes/fieldset.html, error at line 4
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
- 更新 -
该问题仅出现在管理区域中.
- 更新2 -
也许跟踪转储提供了更多信息:
Original Traceback (most recent call last):
File "/Library/Python/2.5/site-packages/django/template/debug.py", line 71, in render_node
result = node.render(context)
File "/Library/Python/2.5/site-packages/django/template/defaulttags.py", line 155, in render
nodelist.append(node.render(context))
File "/Library/Python/2.5/site-packages/django/template/defaulttags.py", line 239, in render
value = bool_expr.resolve(context, True)
File "/Library/Python/2.5/site-packages/django/template/__init__.py", line 546, in resolve …Run Code Online (Sandbox Code Playgroud) django ×1