开发者

How to render HTML form from schema using formencode?

I'm using开发者_如何学Python formencode for validating and submitting forms in my Pylons application. The documentation says that it can be used also for generating forms, but there is no any example. I even found the old topic which says it can be done with

form = HTMLForm(form_template, FormSchema)
form.render()

but for the latest version of formencode it doesn't work.

So, someone please help, how can I generate a HTML using the simplest form Schema?

class LoginForm(formencode.Schema):
    allow_extra_fields = True
    filter_extra_fields = True
    email = formencode.validators.String(not_empty=True)
    password = formencode.validators.String(not_empty=True)


Formencode library doesn't generate html for forms.

The code you are referring to uses formencode.htmlform module which no longer exists as it was removed in 1.1 release because, as author said, it was dumb. :)

I think you may have mistaken that kind of functionality with different feature of this lib, namely filling form values after unsuccessful submission which is realised by formencode.htmlfill module.


What zifot said about formencode was spot on. I would only add that you should look at FormAlchemy and Sprox, two libraries built to generate forms from database schemas.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜