formencode 返回类型无效

发布于 2024-07-25 19:58:23 字数 539 浏览 4 评论 0原文

如果表单编码发生异常那么返回类型是什么?

假设

if(request.POST):
        formvalidate = ValidationRule()
        try:
            new = formvalidate.to_python(request.POST)
            data = Users1( n_date = new['n_date'], heading = new['heading'], 
                           desc = new['desc'], link = new['link'], 
                           module_name = new['module_name'] )
            session.add(data)
            session.commit()
        except formencode.Invalid, e:
            errors = e

我们如何找到现场误差

if an exception occurs in form encode then what will be the return type??

suppose

if(request.POST):
        formvalidate = ValidationRule()
        try:
            new = formvalidate.to_python(request.POST)
            data = Users1( n_date = new['n_date'], heading = new['heading'], 
                           desc = new['desc'], link = new['link'], 
                           module_name = new['module_name'] )
            session.add(data)
            session.commit()
        except formencode.Invalid, e:
            errors = e

how we can find the field wise error

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情归归情 2024-08-01 19:58:23

我假设您正在使用 formencode(http://formencode.org)

您可以使用 unpack_errors 获取每个字段错误,

import formencode
from formencode import validators

class UserForm(formencode.Schema):
    first_name = validators.String(not_empty=True)
    last_name = validators.String(not_empty=True)

form = UserForm()
try:
    form.to_python({})
except formencode.Invalid,e:
    print e.unpack_errors()

例如将打印每个字段的错误字典。

您可以使用 formencode.htmlfill.render 以不同的方式呈现所有错误,请阅读
http://formencode.org/htmlfill.html#errors

I assume you are using formencode(http://formencode.org)

you can use unpack_errors to get per field error e.g.

import formencode
from formencode import validators

class UserForm(formencode.Schema):
    first_name = validators.String(not_empty=True)
    last_name = validators.String(not_empty=True)

form = UserForm()
try:
    form.to_python({})
except formencode.Invalid,e:
    print e.unpack_errors()

it will print a dict of errors per field.

you can use formencode.htmlfill.render to render all errors, in different ways, read
http://formencode.org/htmlfill.html#errors

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文