- Building Serverless Python Web Services with Zappa
- Abdulwahid Abdulhaque Barguzar
- 155字
- 2021-07-16 18:16:19
Forms
Flask-WTF extensions provide the ability to develop forms in Flask and render them through Jinja2 templates. Flask-WTF extends the WTForms library, which has standard patterns to design a form.
We need two forms for this, such as SignupForm and LoginForm. The following is the code for creating forms classes.
File—auth/forms.py:
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField
from wtforms.validators import Required, Length, Email, EqualTo
class LoginForm(FlaskForm):
email = StringField(
'Email', validators=[Required(), Length(1,64), Email()]
)
password = PasswordField(
'Password', validators=[Required()]
)
submit = SubmitField('Log In')
class SignupForm(FlaskForm):
email = StringField(
'Email', validators=[Required(), Length(1,64), Email()]
)
password = PasswordField(
'Password', validators=[
Required(),
EqualTo('confirm_password', message='Password must match.')]
)
confirm_password = PasswordField(
'Confirm Password', validators=[Required()]
)
submit = SubmitField('Sign up')
Here, we create the forms with some validations. Now, we are going to use these forms in the views section, where we are going to render the templates along with the forms context.
推薦閱讀
- 黑客攻防實戰技術完全手冊:掃描、嗅探、入侵與防御
- 物聯網工程規劃技術
- 物聯網短距離無線通信技術應用與開發
- 局域網組建、管理與維護項目教程(Windows Server 2003)
- 面向物聯網的嵌入式系統開發:基于CC2530和STM32微處理器
- Metasploit Penetration Testing Cookbook
- 從實踐中學習手機抓包與數據分析
- 精通SEO:100%網站流量提升密碼
- NB-IoT原理和優化
- Cisco無線局域網配置基礎
- 走近奇妙的物聯網
- ReasonML Quick Start Guide
- Building Microservices with Spring
- 從實踐中學習Kali Linux網絡掃描
- LiveCode Mobile Development Beginner's Guide