当前位置:网站首页>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 ).
边栏推荐
- Research on cooperative control of industrial robots
- SWC introduction
- Tidb ecological tools (backup, migration, import / export) collation
- Tomb. Weekly update of Finance (February 7 - February 13)
- Map sorts according to the key value (ascending plus descending)
- Microsoft Research, UIUC & Google research | antagonistic training actor critic based on offline training reinforcement learning
- Force buckle 1189 Maximum number of "balloons"
- Princeton University, Peking University & UIUC | offline reinforcement learning with realizability and single strategy concentration
- 教你用Pytorch搭建一个自己的简单的BP神经网络( 以iris数据集为例 )
- mysqldump数据备份
猜你喜欢
Microsoft Research, UIUC & Google research | antagonistic training actor critic based on offline training reinforcement learning
The next industry outlet: NFT digital collection, is it an opportunity or a foam?
StrError & PERROR use yyds dry inventory
Suggestions for new engineer team members
Computer graduation project asp Net fitness management system VS development SQLSERVER database web structure c programming computer web page source code project
BUAA计算器(表达式计算-表达式树实现)
Pytoch foundation - (1) initialization of tensors
Record the process of reverse task manager
1.16 - 校验码
Tomb. Weekly update of Finance (February 7 - February 13)
随机推荐
遥感图像超分辨重建综述
SWC introduction
2.2 fonctionnement stm32 GPIO
Idea push rejected solution
Buuctf question brushing notes - [geek challenge 2019] easysql 1
Image super-resolution using deep convolutional networks(SRCNN)解读与实现
Problems encountered in 2022 work IV
A brief introduction to symbols and link libraries in C language
Computer graduation project asp Net fitness management system VS development SQLSERVER database web structure c programming computer web page source code project
Crazy, thousands of netizens are exploding the company's salary
Force buckle 1189 Maximum number of "balloons"
施努卡:3d视觉检测应用行业 机器视觉3d检测
1.16 - 校验码
Edcircles: a real time circle detector with a false detection control translation
Remote Sensing Image Super-resolution and Object Detection: Benchmark and State of the Art
下一个行业风口:NFT 数字藏品,是机遇还是泡沫?
适合程序员学习的国外网站推荐
IPv6 comprehensive experiment
2、GPIO相关操作
3857墨卡托坐标系转换为4326 (WGS84)经纬度坐标