Простой пример формы(http://deformdemo.xo7.de/nonrequiredfields/):
class Schema(colander.Schema):
required = colander.SchemaNode(
colander.String(),
description='Required Field'
)
notrequired = colander.SchemaNode(
colander.String(),
missing=unicode(''),
description='Unrequired Field')
schema = Schema()
form = deform.Form(schema, buttons=('submit',))
return self.render_form(form)
К полям можно добавлять описание, но если вставить html то он заэскапируется(https://github.com/Pylons/deform/blob/bb4fc86913884deafa9350de86d87fb5232263fa/deform/templates/form.pt#L42). Можно воспользоваться хитрой возможностью Chamelon'а что бы вывести html.
class HTMLText(object):
def __init__(self, text):
self.text = text
def __html__(self):
return unicode(self.text)
notrequired = colander.SchemaNode(
colander.String(),
missing=unicode(''),
description=HTMLText('Hello <hr color="red" /> World!!! <hr />'))
Chameleon по умолчанию ищет метод __html__ у объектов и если он есть то выводит его результат в чистом виде. Вот.
Комментариев нет:
Отправить комментарий