用于生成和验证HTML表单的库
BlazeForm的Python项目详细描述
简介
blazeform是一个库,旨在方便呈现/处理/验证 HTML表单的。
功能
- 基于formencode的验证
- 试图获得完整的HTML规范覆盖率
- 可扩展渲染系统()(不必使用它)
- 将与多个wsgi框架一起工作(目前支持werkzeug)
- 广泛的单元测试
- 少数依赖项:formencode、blazeutils、webhelpers2
代码示例
使用它可能会像这样:
class MyForm(Form): def __init__(self): Form.__init__(self, 'myform') el = self.els.add_header('input-els', 'Optional Elements') el = self.els.add_button('button', 'Button', defaultval='PushMe') el = self.els.add_checkbox('checkbox', 'Checkbox') el = self.els.add_file('file', 'File') el = self.els.add_hidden('hidden', defaultval='my hidden val') el = self.els.add_image('image', 'Image', defaultval='my image val', src='images/icons/b_edit.png') el = self.els.add_text('text', 'Text') el.add_note('a note') el.add_note('an <strong>HTML</strong> note', False) el = self.els.add_text('nolabel', defaultval='No Label') el.add_note('a note') el = self.els.add_password('password', 'Password') el = self.els.add_confirm('confirm', 'Confirm Password', match='password') el.add_note('confirm characters for password field are automatically masked') el = self.els.add_date('date', 'Date', defaultval=datetime.date(2009, 12, 3)) el.add_note('note the automatic conversion from datetime object') emel = self.els.add_email('email', 'Email') el = self.els.add_confirm('confirmeml', 'Confirm Email', match=emel) el.add_note('note you can confirm with the name of the field or the element object') el.add_note('when not confirming password field, characters are not masked') el = self.els.add_time('time', 'Time') el = self.els.add_url('url', 'URL') options = [('1', 'one'), ('2','two')] el = self.els.add_select('select', options, 'Select') el = self.els.add_mselect('mselect', options, 'Multi Select') el = self.els.add_textarea('textarea', 'Text Area') el = self.els.add_fixed('fixed', 'Fixed', 'fixed val') el = self.els.add_fixed('fixed-no-label', defaultval = 'fixed no label') el = self.els.add_static('static', 'Static', 'static val') el = self.els.add_static('static-no-label', defaultval='static val no label')
视图/控制器代码可能类似于:
class FormTest(HtmlTemplatePage): def prep(self): self.form = MyForm() def post(self): if self.form.is_cancel(): self.assign('cancel', True) elif self.form.is_valid(): self.assign('values', self.form.get_values()) elif self.form.is_submitted(): # form was submitted, but invalid self.form.assign_user_errors() self.default() def default(self): self.assign('form', self.form)
更改日志
0.4.2发布日期:2018-01-17
- 处理空提交文件上载中的字符串类型
0.4.1发布日期:2017-06-02
- 更新验证消息以确保python版本之间的一致性
0.4.0发布日期:2016-11-23
- 增加了对Python3(3.4和3.5)的支持
- 设置CI和覆盖范围
0.3.9 2016-05-20发布
- make is_empty就输入类型而言更一般,0不应为空
0.3.8发布日期:2016-02-24
- 更新与formencode的兼容性以包含1.3
0.3.7 2014-10-27发布
- 修正checkbox元素,将空值作为ie 9/10 compat的on/true处理。
0.3.6 2014-10-15发布
- 允许逻辑组使用标签,如单选按钮或复选框
0.3.5发布日期2014-08-20
- 确保表单验证器和元素处理器是fe验证器 是实例
0.3.4 2012-07-05发布
- 表单现在有了all_errors()方法,它将表单和字段错误返回为(list, (分别)元组。
- 更新检查文件上载是否发送的方式。以前,我们 正在测试文件名头是否为“无”,但Werkzeug将其作为 文件存储对象中的空字符串。理论上会导致 行为改变,但仅限于狭隘的情况。
0.3.3发布日期:2011-11-16
- textareaelement现在使用maxlength kwarg
0.3.2发布日期:2011-06-11
- 修正0.3.1的破损分布
0.3.1发布日期:2011-06-11
- 修复了验证错误后单选按钮呈现中的错误