问一个基本的问题
来源:7-14 .修改密码-
Ghost
2017-08-04
为啥这两处的field.data的值直接就是account和pwd所需要的值
写回答
1回答
-
同学你好,你可以参考wtforms/form.py的源码,这两个方法是构造出来的类方法,格式是validate_字段名:
def validate(self): extra = {} for name in self._fields: inline = getattr(self.__class__, 'validate_%s' % name, None) if inline is not None: extra[name] = [inline] return super(Form, self).validate(extra)
field字段数据是通过这种方法构造的:
def process(self, formdata=None, obj=None, data=None, **kwargs): formdata = self.meta.wrap_formdata(self, formdata) if data is not None: kwargs = dict(data, **kwargs) for name, field, in iteritems(self._fields): if obj is not None and hasattr(obj, name): field.process(formdata, getattr(obj, name)) elif name in kwargs: field.process(formdata, kwargs[name]) else: field.process(formdata)
field.data你可以具体参考每个字段的process_formdata方法:
def process_formdata(self, valuelist): if valuelist: try: self.data = self.coerce(valuelist[0]) except ValueError: raise ValueError(self.gettext('Invalid Choice: could not coerce'))
022017-08-04
相似问题