Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the function of form and input validation in Flask

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to achieve Flask in the form and input verification function, the editor feels very practical, so share with you to learn, I hope you can get something after reading this article, say no more, follow the editor to have a look.

1. What is Flask-WTF?

Flask-wtf is a form integration plug-in, including CSRF, file upload and Recaptcha integration.

two。 How to use Flask-WTF?

Execute pip install flask-wtf from the command line to install:

First, continue with the previous chapter, create a new file forms.py in the Flask_Blog folder:

To use this form, we need to modify the flaskblog.py by adding a key, first randomly generating a key:

Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32Type "help", "copyright", "credits" or "license" for more information. > > import secrets > secrets.token_hex (16) '037a34afcf9ceba959865d80f69e2d6f' >

Then modify the flaskblog.py:

Then we add the registration and login methods of the form, and modify the flaskblog.py:

Create a new register.html registration page in the folder templates with the following contents:

Create a new login.html login page in the folder templates with the following contents:

Adjust and modify the layout.html in the folder templates, use url_for () for the navigation path, and add the prompt code after login and registration:

Then we open the command line cmd in the folder Flask_Blog and run python falskblog.py:

Visit the address http://127.0.0.1:5000, click the navigation registration link, and enter test data that do not meet the verification rules (the corresponding prompt appears. The default is English prompt, which can be changed to Chinese prompt. If you need to modify the code, you can try it yourself):

After entering data that meets the verification rules, prompt to create an account:

Click the login connection in the navigation and enter a different mailbox and password from the code:

Enter the correct user name and password:

The above is how to achieve the form and input verification functions in Flask. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

  • Mybatis applicationContext.xml configuration method

    # what to do in applicationContext.xml Spring integrate Mybatis configuration

    © 2024 shulou.com SLNews company. All rights reserved.

    12
    Report