WTForms extensions for Tornado.
import tornado.ioloop import tornado.web from wtforms.fields import IntegerField from wtforms.validators import DataRequired from wtforms_tornado import Form class SumForm(Form): a = IntegerField(validators=[DataRequired()]) b = IntegerField(validators=[DataRequired()]) class SumHandler(tornado.web.RequestHandler): def get(self): self.write("Hello, world") def post(self): form = SumForm(self.request.arguments) if form.validate(): self.write(str(form.data['a'] + form.data['b'])) else: self.set_status(400) self.write("" % form.errors) application = tornado.web.Application([ (r"/", SumHandler), ]) if __name__ == "__main__": application.listen(8888) tornado.ioloop.IOLoop.instance().start()
You can to use pip to install WTForms-Tornado:
$ pip install wtforms-tornado
Or using last source:
$ pip install git+git://github.com/puentesarrin/wtforms-tornado.git
Or manually, download the latest source from PyPI:
$ tar xvzf wtforms-tornado-$VERSION.tar.gz $ cd wtforms-tornado-$VERSION $ python setup.py build $ sudo python setup.py install