当前位置:网站首页>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 ).
边栏推荐
- The solution of permission denied (750 permissions should be used with caution)
- JS Vanke banner rotation chart JS special effect
- SD card reports an error "error -110 whilst initializing SD card
- mysqldump数据备份
- SAP ALV color code corresponding color (finishing)
- Tomb. Weekly update of Finance (February 7 - February 13)
- 3857墨卡托坐标系转换为4326 (WGS84)经纬度坐标
- BUAA magpie nesting
- Item 10: Prefer scoped enums to unscoped enums.
- Remote Sensing Image Super-resolution and Object Detection: Benchmark and State of the Art
猜你喜欢

Pointer for in-depth analysis (problem solution)

Mysqldump data backup

Princeton University, Peking University & UIUC | offline reinforcement learning with realizability and single strategy concentration

Overview of OCR character recognition methods

深入刨析的指针(题解)

下一个行业风口:NFT 数字藏品,是机遇还是泡沫?

BUAA喜鹊筑巢

Derivation of anti Park transform and anti Clarke transform formulas for motor control

SWC introduction

Pytorch load data
随机推荐
MADDPG的pythorch实现——(1)OpenAI MADDPG环境配置
Tomb. Weekly update of Finance (February 7 - February 13)
Recommended papers on remote sensing image super-resolution
Overview of super-resolution reconstruction of remote sensing images
[slam] orb-slam3 parsing - track () (3)
Polymorphic day02
Shell 传递参数
Research on cooperative control of industrial robots
Crazy, thousands of netizens are exploding the company's salary
Schnuka: visual positioning system working principle of visual positioning system
Brush questions in summer -day3
. Net 6 and Net core learning notes: Important issues of net core
Idea push rejected solution
Record the process of reverse task manager
Inherit day01
These are not very good
three. JS page background animation liquid JS special effect
Crawler of explanation and application of agency theory
3.2 rtthread 串口设备(V2)详解
【RISC-V】外部中断