Python Flask Tutorial #3 - Forms and User Input

· 6년 전 · 1073

https://youtu.be/UIJKdCIEXUQ?list=PL-osiE80TeTs4UjLw5MM6OjgkjFeUxCYH

 

WTFform을 사용해서 register 하는 방법과

flash를 사용해서 상단에 message를 뿌려 주는 방법 (status: Success, Info, Error등)

각 필드에 대한 Validation 그리고 error 메시지 처리까지

 

먼저 https://flask-wtf.readthedocs.io/en/stable/  를 인스톨합니다.

Features

  • Integration with WTForms.
  • Secure Form with CSRF token.
  • Global CSRF protection.
  • reCAPTCHA support.
  • File upload that works with Flask-Uploads.
  • Internationalization using Flask-Babel.

 

pipenv install flask-wtf

 

from flask_wtf import FlaskForm

from wtforms import StringField, PasswordField, SubmitField, BooleanField

from wtforms.validators import DataRequired, Length, Email, EqualTo

 

class RegistrationForm(FlaskForm):

    username = StringField('Username', 

                    validators=[DataRequired(), Length(min=2, max=20)])

    email = StringField('Email',

                    validators=[DataRequired(), Email()])

    password = PasswordField('Password', 

                    validators=[DataRequired()])

    confirm_password = PasswordField('Confirm Password', 

                    validators=[DataRequired(), EqualTo('password')])

    

    submit = SubmitField('Sign Up')

 

class LoginForm(FlaskForm):

    email = StringField('Email',

                    validators=[DataRequired(), Email()])

    password = PasswordField('Password', validators=[DataRequired()])

    remember = BooleanField('Remember Me')

    submit = SubmitField('Login')

 

이 두줄은 Flask에 내장된 함수 같습니다.

from wtforms import StringField, PasswordField, SubmitField, BooleanField

from wtforms.validators import DataRequired, Length, Email, EqualTo

 

1808292852_1575566403.5648.png

 

Login 까지...

 

1808292852_1575567270.1016.png

|
댓글을 작성하시려면 로그인이 필요합니다. 로그인

파이썬 게시판 만들기

+
제목 글쓴이 날짜 조회
6년 전 조회 1,321
6년 전 조회 1,265
6년 전 조회 904
6년 전 조회 705
6년 전 조회 982
6년 전 조회 1,610
6년 전 조회 1,084
6년 전 조회 814
6년 전 조회 1,157
6년 전 조회 773
6년 전 조회 995
6년 전 조회 1,196
6년 전 조회 1,016
6년 전 조회 1,403
6년 전 조회 1,074
6년 전 조회 970
6년 전 조회 940
6년 전 조회 2,294
6년 전 조회 854
6년 전 조회 2,364
6년 전 조회 849
6년 전 조회 966
6년 전 조회 1,003
6년 전 조회 1,224
6년 전 조회 920
6년 전 조회 947
6년 전 조회 961
6년 전 조회 1,067
6년 전 조회 819
6년 전 조회 713
🐛 버그신고