Python Flask Tutorial #3 - Forms and User Input

· 6년 전 · 1070

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년 전 조회 704
6년 전 조회 982
6년 전 조회 1,610
6년 전 조회 1,084
6년 전 조회 813
6년 전 조회 1,155
6년 전 조회 771
6년 전 조회 993
6년 전 조회 1,196
6년 전 조회 1,016
6년 전 조회 1,400
6년 전 조회 1,071
6년 전 조회 970
6년 전 조회 939
6년 전 조회 2,292
6년 전 조회 854
6년 전 조회 2,361
6년 전 조회 848
6년 전 조회 964
6년 전 조회 1,003
6년 전 조회 1,224
6년 전 조회 919
6년 전 조회 945
6년 전 조회 958
6년 전 조회 1,067
6년 전 조회 816
6년 전 조회 712
🐛 버그신고