当前位置:网站首页>Flask learning and project practice 9: WTF form verification
Flask learning and project practice 9: WTF form verification
2022-07-06 03:36:00 【Study notes of Zhou】
1.WTF Introduction to form validation
Flask-WTF It's simplified WTForms A third-party library for operations .WTForms The two main functions of the form are to verify the legitimacy of the data submitted by the user and render the template . Of course, it also includes some other functions :CSRF Protect , File upload, etc . install Flask-WTF It will also be installed by default WTForms, So use the following command to install Flask-WTF: pip install flask-wtf
.
For example, log in when you go to Taobao , First check whether the user input meets the conditions , If you are not satisfied, you will not check the database . namely Verify whether the requirements are met before querying the database .
WTForms It can also be used in other frameworks , Such as django etc. . and Flask This third-party library is specially simplified , To facilitate the operation of the project .
2. Perform form validation
validators Just pass some validation parameters in for comparison .
The code is as follows :
class RegistForm(Form):
name = StringField(validators=[length(min=4,max=25)])
email = StringField(validators=[email()])
password = StringField(validators=[DataRequired(),length(min=6,max=10),EqualTo('confirm')])
confirm = StringField()
DataRequired It means that the password must be entered ,EqualTo(‘confirm’) Must be equal .
3. Code implementation
stay action Which means , When the button is clicked , To which url.
method It refers to the request method . And also notice that input Of name It needs to correspond to your own settings .
If the authenticator of the mailbox is missing , have access to pip install email_validator To install .
At the same time, the above code needs to be improved , That is, for views, only GET, Need to increase the post As shown in the figure below :
So you can verify .( Initially relieve the pressure on the database ).
边栏推荐
- MySQL Server层四个日志
- 教你用Pytorch搭建一个自己的简单的BP神经网络( 以iris数据集为例 )
- Shell pass parameters
- Exness foreign exchange: the governor of the Bank of Canada said that the interest rate hike would be more moderate, and the United States and Canada fell slightly to maintain range volatility
- 简述C语言中的符号和链接库
- ESBuild & SWC浅谈: 新一代构建工具
- Cross origin cross domain request
- Restful style
- 给新人工程师组员的建议
- JS Vanke banner rotation chart JS special effect
猜你喜欢
Explore pointers and pointer types in depth
SAP ALV cell level set color
真机无法访问虚拟机的靶场,真机无法ping通虚拟机
Cubemx 移植正点原子LCD显示例程
1.16 - check code
Pytoch foundation - (1) initialization of tensors
Microsoft Research, UIUC & Google research | antagonistic training actor critic based on offline training reinforcement learning
Force buckle 1189 Maximum number of "balloons"
【RISC-V】外部中断
Suggestions for new engineer team members
随机推荐
Deep parsing pointer and array written test questions
Item 10: Prefer scoped enums to unscoped enums.
RT thread -- FTP of LwIP (2)
关于非虚函数的假派生
ASU & OSU | model based regularized off-line meta reinforcement learning
IPv6 comprehensive experiment
Safety science to | travel, you must read a guide
Crazy, thousands of netizens are exploding the company's salary
The next industry outlet: NFT digital collection, is it an opportunity or a foam?
Deno介绍
2.1 rtthread pin设备详解
Microsoft Research, UIUC & Google research | antagonistic training actor critic based on offline training reinforcement learning
Mysql database operation
Leetcode problem solving -- 99 Restore binary search tree
Analyze menu analysis
Performance test method of bank core business system
three.js网页背景动画液态js特效
pytorch加载数据
Pytorch基础——(2)张量(tensor)的数学运算
Eight super classic pointer interview questions (3000 words in detail)