金字塔和金字塔中的Formencode_simplefrom:设置为固定

2024-06-08 23:26:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我知道我可以在python shell中运行以下代码:

import formencode
ne = formencode.validators.NotEmpty()
formencode.api.set_stdtranslation(languages=["it"])
try:
    ne.to_python("")
except formencode.api.Invalid, e:
    print str(e)

然后打印出来

Inserire un valore

现在,如何在我的金字塔应用程序中使用pyramid\u simpleform和Formencode获得相同的结果?在


Tags: to代码importapiitshellformencodene
1条回答
网友
1楼 · 发布于 2024-06-08 23:26:15

我刚刚找到了一个方法,但我不确定这是最好的方法。。。不管怎样,我混合了来自Mako i18n recipesimpleform documentation的信息以及塔架是如何做到的(内部的PylonsFormEncodeState)塔架、装饰工)我想到了以下几点。。。在

我订阅一个新请求事件,如下所示:

config.add_subscriber("myproject.subscribers.add_localizer",
                      "pyramid.events.NewRequest")

然后定义add_localizer

^{pr2}$

相关问题 更多 >