wtforms json schema将wtforms转换为json模式兼容表示
wtforms-jsonschema的Python项目详细描述
简介
wtforms json schema将wtforms转换为json模式兼容表示形式
要求
- python 2.6或更高版本
- W表格
用法
将表单转换为json模式:
from wtforms_jsonschema.jsonschema import WTFormToJSONSchema schema_repr = WTFormToJSONSchema().convert_form(MyForm)
TOdo:将JSON架构嵌入为表单字段:
from wtforms_jsonschema.forms import JSONSchemaField #where schema is a python dictionay like schema_repr in the first exmaple class MyForm(forms.Form): subfield = JSONSchemaField(schema=schema) form = MyForm(data={'subfield':'<json encoded value>'}) form.validate() #will validate the subfield entry against schema form['subfield'].as_widget() #will render a textarea widget with a data-schemajson attribute