我正在学习 Django。特别是我正在阅读有关表格的内容,但我无法理解它们是如何工作的。让我们看一下示例代码:
from django import forms
class ContactForm(forms.Form):
subject = forms.CharField(max_length=100)
message = forms.CharField()
sender = forms.EmailField()
cc_myself = forms.BooleanField(required=False)
为什么要创建具有无限成员的类?没有self
声明。
我查看了 Django 源代码本身:
class Form(BaseForm):
"A collection of Fields, plus their associated data."
# This is a separate class from BaseForm in order to abstract the way
# self.fields is specified. This class (Form) is the one that does the
# fancy metaclass stuff purely for the semantic sugar -- it allows one
# to define a form using declarative syntax.
# BaseForm itself has no way of designating self.fields.
__metaclass__ = DeclarativeFieldsMetaclass
你能解释一下它的作用是__metaclass__
什么吗?