为什么使用 WTForms 而不是仅使用 HTML 发布 [英] Why use WTForms instead of just posting with HTML

查看:22
本文介绍了为什么使用 WTForms 而不是仅使用 HTML 发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近很好奇使用 WTForms 向烧瓶提交数据的好处是什么?纯 HTML、JavaScript 或引导程序表单似乎更易于设计样式并更易于提交.此外,您可以省略创建 WTForms 类所需的所有 Python 代码.有人可以解释一下什么是优势吗?

I've been curious lately what the benefits of using WTForms to submit data to flask is? Plain HTML, JavaScript, or bootstrap form seem easier to style and easier to submit with. Plus you can leave out all the python code required to create a WTForms class. Can someone explain what an advantage would be?

推荐答案

我可以说 CSRF protection 是最大的原因之一,但有很多原因为什么人们会使用 WTFroms 而不是普通的HTML 表单.

I could say CSRF protection is one of the greatest reasons, but there are a lot of reasons why one would use WTFroms over plain HTML forms.

  • 开箱即用的CSRF保护
  • 开箱即用的表单验证
  • WTForms 作为类出现,所以所有的好处都来自对象形式.

基本上,如果您的项目有很多看起来相同但有细微差别的表单,那么 WTForms 会很有帮助.

basically, if your project has a lot of form's looking the same with minor differences, WTForms would be of great help.

然后您就拥有了开箱即用的验证,您对电子邮件和所有其他类型的数据使用简单的验证,它们就在那里,无需费心编写自己的验证器并继续维护它们.

and then you have validations out of the box, you use a simple validation for Email and all other kind's of data, and they are there, no need to bother with writing your own validators and keep maintaining them.

CSRF 是 owasp 十大攻击之一[1],所以对此提供良好的保护非常重要.

CSRF is one of the owasp top 10 attacks[1], so providing good protection over this is really important.

这篇关于为什么使用 WTForms 而不是仅使用 HTML 发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆