python表单验证库推荐
我想要一个表单验证库,
1.将 html 生成与表单验证分开;
2.验证错误可以很容易地序列化,例如。转储为 json 对象
您会在 python Web 项目中选择什么表单验证库?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我想要一个表单验证库,
1.将 html 生成与表单验证分开;
2.验证错误可以很容易地序列化,例如。转储为 json 对象
您会在 python Web 项目中选择什么表单验证库?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
免责声明
一般来说,我现在对 HTML 表单库有点警惕。如果您使用大型框架中的某些内容,那么您总是必须引入整个大型框架作为您的依赖项。
许多大型框架的许多子组件都声称不依赖于该框架,但我们不要欺骗自己。如果您不使用其中一个,据我所知,至少有十几个表单库,它们的功能存在很大差异。光是选择就可能会变得相当混乱。一般来说,正如 Ian Bicking 多年前所说的,我认为现在仍然如此一种适合所有人的表单库的想法是相当可笑的。事实上,我认为您可能需要三思而行,然后再决定是否真的需要一个。大多数情况下,您只需要一个表单验证库,例如 FormEncode。这实际上取决于您想如何使用它。
对我来说,因为我不使用大型框架,所以我会选择一些轻量级的、易于拾取和配置的东西,并且不会妨碍 HTML/JS/CSS 的正常使用。
END 免责声明
我尝试过 ToscaWidgets、ToscaWidgets、ToscaWidgets 2, Formish ,变形,WTForms 和 FormEncode。我不得不说,它们都不是完美的。以下是我对它们的体验:
截至 2012 年底,通过 Google 和 PyPI 快速搜索 Python 验证库,会得到数百个包。除去那些正在积极开发的 Django 扩展,还有十几个值得注意的扩展。似乎有一种趋势是使用 JSON-Schema 定义架构并能够通用地验证 Python 数据结构。这可能反映了服务器应用程序开发人员正在从多个渠道(RESTful API 和 HTML 表单)接受用户数据,但仍然希望只使用一个验证库。
鉴于 Python 3.3 的发布可能会引发一场大规模的迁移现有库以支持 Python 3.x 的运动(另一方面,旧库停滞不前,仅与 Python 2.x 兼容),因此明智的做法可能是选择已经支持或正在积极支持 Python 3.x 的一个。
最后,选择表单验证库时需要关注的另一个重要方面是报告有用的错误消息的能力,从长远来看,这总是需要本地化错误消息。提供您自己的错误消息的难易程度将很快决定将该库与 Web 应用程序体系结构的其余部分集成的复杂性。
有前途的后起之秀:
Disclaimer
Generally speaking I'm a little wary about HTML form libraries now. If you use something from a mega-framework, you invariably have to bring in the whole mega-framework as your dependency.
Many sub-components of many mega-frameworks claim to not depend on the framework but let's not kid ourselves. If you don't use one, there are at least a dozen form libraries that I know of out there with a wide range of differences in capabilities. Just the choices alone can get quite confusing. Generally speaking, as Ian Bicking says many years ago and is still true, I think the notion of one form library that suits everybody is quite ludicrous. In fact I'd argue you probably need to think twice before deciding you really need one. Chances are mostly of the time you just need a form validation library like FormEncode. It really depends on how you want to use it.
For me, since I don't use a mega-framework, I'd choose something light-weight, easy to pick up and configure, and something that doesn't get in the way of the normal usage of HTML/JS/CSS.
END Disclaimer
I've tried ToscaWidgets, ToscaWidgets 2, Formish, Deform, WTForms and FormEncode. I have to say none of them is anywhere near perfect. Here's my experience with them:
As of the end of 2012, a quick Google and PyPI search for a Python validation library comes back with hundreds of packages. There are a little more than a dozen notable ones, discounting those Django extensions, that are under active development. There seems to be a trend towards defining a schema using JSON-Schema and being able to generically validate Python data structures. This is likely a reflection of the server application developers' moving accepting user data from multiple channels (RESTful APIs and HTML forms), but remain wanting to use only one validation library.
Given the release of Python 3.3 will likely spark a massive movement towards porting existing libraries over to support Python 3.x (the flip side of that is seeing old libraries stagnant and remain compatible only with Python 2.x), it may be wise to choose one that already supports or is working actively to support Python 3.x.
Lastly, another great area of concern when choosing a form validation library is the ability to report useful error messages, which invariably includes the need for the localization of error messages in the long run. The ease of supplying your own error messages will quickly determine the complexity of integrating the library with the rest of your Web application architecture.
Promising up-and-comers:
我可能会选择 WTForms。
I'd probably pick WTForms.
这个主题有点老了,但我想我会无耻地插入一个我为此目的而编写的库。它并不是 HTML 表单所独有的,而是在编写时(至少部分地)考虑到了 HTML 表单。
当我命名它时,我并没有觉得很有创意,所以现在必须使用“Validator”。给你:https://github.com/wilhelm-murdoch/Validator
This topic is a bit on the old side, but I thought I'd shamelessly plug a library I've been writing for this very purpose. It's not exclusive to HTML forms, but was written with them, at least partially, in mind.
I wasn't feeling very creative when I named it, so "Validator" will have to do for now. Here you go: https://github.com/wilhelm-murdoch/Validator
这取决于天气,然后取决于您使用什么类型的框架。
对于您的任务,我建议您使用 web2py-Framework,这很简单使用并且仍然“强大”。它默认具有表单验证(web2py-book 是免费的),这正是您想要的:它将 html 生成与验证分开并自动执行此操作,但您可以,如果您愿意,可以定制它。
示例:
也可以序列化错误,但对于这些问题,最好在 web2py- 上询问他们组。他们非常友善并且会很快为您提供帮助。
希望有帮助!此致..
It depends wheather, and then, what type of framework you use.
For your task, I would recommend you to use the web2py-Framework, which is easy to use and still "mighty". It has form-validation by default (the web2py-book is free), that does exactly what you want: It sepereates the html generation from the validation and does this automatically, but you can, if you wish, customize it.
An example:
It's also possible to serialize errors, but for those questions it's the best to ask them on the web2py-group. They're very nice and will help you very fast.
Hope it helps! Best regards..
这取决于您使用的底层框架。
对于 django 来说,内置表单框架是最好的,
而 kay 使用 zine 表单系统的扩展版本
,tipfy 使用 WTForms。
django 的内置系统是迄今为止最好的。
你在后台使用什么框架?
it depends on what underlying framework you use.
for django , built in form framework is best,
while kay uses extended version of zine's form system
and tipfy uses WTForms.
django's built in system is best so far .
what framework do you use under the hood ?