WTForms for efficient forms validation and rendering in Flask

preview_player
Показать описание


In this video, we will learn how to use WTForms for easy forms validation and redndering

Please subscribe, like and share this video

00:00 - Intro
00:56 - Install WTForms
01:17 - The Example
01:37 - Basic Server Setup
02:46 - Form Object
03:28 - StringField
04:57 - Render Form in Template
07:34 - HTML attributes in form fields
08:43 - Handle Form submission
11:04 - IntegerField
12:30 - DateTimeField
14:17 - Extract Form Data
15:22 - PasswordField
16:14 - BooleanField
17:10 - TextAreaField
18:04 - SelectField
19:40 - Review the generated Form
20:28 - validate and display errors
22:41 - macros for form fields
24:10 - style the errors with css
24:50 - custom form validation
26:47 - Outro

#flask #wtforms #server #web #forms #jinja #jinja_macro #dev #tutorial #learning #beginners #pythonforbeginners #taming_python
Рекомендации по теме
Комментарии
Автор

How is it that there is always an Indian tutorial with specifically what I need and always with little to no subs :D ! Great work my man, love indian tutorials !

Next-Best-Ai
Автор

thank u so much man. there are very little resources abt learning the newer version of flask. this rly helped me understand it more

biancafiedalan
Автор

Great work i am very easy to understand. Thanks

khurramwali
Автор

He is very good. I learned alot with this video.

TheEducatedandproud
Автор

Thanks a lot🙏🙏🙏 Please keep up the great work, loved the video.

vigneshshetty
Автор

Thank you! A very thorough explanation of WTForms. One question: How can I change the color of the server side validation error messages to red? I tried styling the ul errors class, but that did not work.

raauger
Автор

Exactly what I was looking for!

is the default behavior for the fields to remain populated when the form is submitted?

dannyezechukwu
Автор

Nice bro its really help me
Thanks a lot bro

kartikprajapati
Автор

How can I format the datefield as format= '%d-%m-%Y'? I change it but in my post request it gets sent as Y m d and doesn't validate

claudiapol
Автор

hey i had a problem whenever i click on submit a page 404 error shows and i couldn't understand the reason behind this !!! this is my function
@app.route('/registration', methods=['GET', 'POST'])
def registration_page():
form = RegisterForm()
if form.validate_on_submit():
hashed_password = generate_password_hash(form.password1.data, method='sha256')
user_to_create = User(username=form.username.data,
email_address=form.email_address.data,



db.session.commit()
flash('Thanks for registering')
return
if form.errors != {}: #If there are not errors from the validations
for err_msg in form.errors.values():
print(f'There was an error with creating a user: {err_msg}')

return render_template('registration.html', form=form)

and this is in the registration.html
<form method="POST" action="/registration_page" style="border:1px solid #ccc;padding-bottom: 5%;">
{{form.hidden_tag()}}
{{ form.csrf_token }}
<div class="container">
<h1>Sign Up</h1>
<p>Please fill in this form to create an account.</p>
<hr>
{{ form.username.label() }}
{{ form.username(class="form-control", placeholder="User Name") }}

{{ form.email_address.label() }}
{{ form.email_address(class="form-control", placeholder="Email Address") }}

{{ form.password1.label() }}
{{ form.password1(class="form-control", placeholder="Password") }}

{{ form.password2.label() }}
{{ form.password2(class="form-control", placeholder="Confirm Password") }}

<br>


{{ form.submit(class="btn btn-lg btn-block btn-primary", style="background-color: #5072A7;") }}

</div>
</form>

MA-tvdz
Автор

What can be done if I need to link my mySQL db to Wtforms to check duplicate entries

gaganashetty
Автор

How do you make the form reset its fields (i mean fields become empty) after repfreshing or after error is thrown? in my case after i fill in the fields I get errors but all the values I have input are still there.

mihaelacostea
Автор

1) How do you get the email and password data using wtform using EmailField and PasswordField,
It always return none ?

2) My form validates on refresh and when the form is filled and the validates() method is triggered the form returns false

scratchcode