Python 表单验证、渲染开发包 WTForms

openkk 13年前
     WTForms 是一个 Python 表单验证、渲染开发包,只需要以如下形式定义一个表单:    <pre class="brush:python; toolbar: true; auto-links: false;">class MyForm(Form):      first_name = TextField(u'First Name', validators=[validators.required()])      last_name  = TextField(u'Last Name', validators=[validators.optional()])</pre>    <p></p>    <pre class="brush:python; toolbar: true; auto-links: false;">def register(request):      form = RegistrationForm(request.POST)      if request.method == 'POST' and form.validate():          user = User()          user.username = form.username.data          user.email = form.email.data          user.save()          redirect('register')      return render_response('register.html', form=form)</pre>    <br /> 就可以整合表单的验证、HTML 渲染于一体。    <p></p>    <p>该库可以通过 <em>easy_install WTForms</em> 被安装。<br /> 下载:<span style="white-space:nowrap;"><a href="/misc/goto?guid=4958192179218050652">WTForms-0.6.3.zip</a> (<a title="MD5 Digest" href="http://pypi.python.org/pypi?:action=show_md5&digest=e0a64ff0b37b925e03621446cbfdba85">md5</a>) </span><br /> <img title="Python 表单验证、渲染开发包 WTForms" border="0" alt="Python 表单验证、渲染开发包 WTForms" src="https://simg.open-open.com/show/8a8179364d1b8098c5a12c0df9a643c2.jpg" width="243" height="69" /></p>