class Form(Form):
def forms(self):
name = TextField('name', validators=[Required()])
class IndexHandler(tornado.web.RequestHandler):
def get(self):
form = Form()
self.render('index.html', form=form.forms())
模板:
<form method="post" action="/test">
{% raw form.name(type='text') %}
</form>
错误:
AttributeError:“NoneType”对象没有属性“名称”
然而,这可行,但我需要类Form中的一个函数:
class Form(Form):
name = TextField('name', validators=[Required()])
class IndexHandler(tornado.web.RequestHandler):
def get(self):
form = Form()
self.render('index.html', form=form)