Questions tagged [flask-wtforms]

Flask-WTF offers simple integration with WTForms. This integration includes optional CSRF handling for greater security.

Flask-WTF offers simple integration with WTForms. This integration includes optional CSRF handling for greater security.

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.

Documentation: https://flask-wtf.readthedocs.io/en/stable/

Github: https://github.com/lepture/flask-wtf

Issue Tracker: https://github.com/lepture/flask-wtf/issues

2348 questions
100
votes
8 answers

Multiple forms in a single page using flask and WTForms

I have multiple form on the same page that send post request to same handler in flask. I am generating forms using wtforms. what is the best way to identify which form is submitted ? I am currently using action="?form=oneform". I think there should…
iamgopal
  • 8,806
  • 6
  • 38
  • 52
42
votes
4 answers

How do you solve the error KeyError: 'A secret key is required to use CSRF.' when using a wtform in flask application?

I have been trying to build a web app using flask and wtforms and a firebase database, but I keep getting the error message "KeyError: 'A secret key is required to use CSRF.'" and I don't know how to solve it. here is my code: from flask import…
32
votes
1 answer

Flask WTForms: Difference between DataRequired and InputRequired

What is difference between DataRequired and InputRequired in wtforms.valiadators I have some fields in my signup form : username password password_repeat submit Should these fields use the DataRequired or InputRequired validator?
Ryan
  • 435
  • 1
  • 4
  • 6
31
votes
1 answer

Get an uploaded file from a WTForms field

In the Flask docs, the file upload example uses then request.files['file'] to get the file. I'm using a WTForms FileField. How do I get the uploaded file when using WTForms rather than writing the input html myself?
Kevin Q
  • 679
  • 1
  • 13
  • 19
30
votes
2 answers

how to implement not-required DateField using Flask-WTF

I want a DateField which is optional, but I got a "Not a valid date value" error if leave it empty I add some logs in the source code of wtforms, and found formdata.getlist(self.name) returns [u''] for this DateField The code of my form: from…
peon
  • 1,833
  • 2
  • 19
  • 21
29
votes
4 answers

Clear valid form after it is submitted

I want to reset the form after it validates. Currently the form will still show the previous data after it is submitted and valid. Basically, I want the form to go back to the original state with all fields clean. What is the correct to do…
user455318
  • 3,280
  • 12
  • 41
  • 66
29
votes
6 answers

Form validation fails due missing CSRF

A few days ago I have reset my local flask environment without having captured the dependencies via a pip freeze before I deleted it. Hence I had to re-install the latest version of the entire stack. Now out of the blue I am no longer able to…
Houman
  • 64,245
  • 87
  • 278
  • 460
28
votes
1 answer

DatePickerWidget with Flask, Flask-Admin and WTforms

I'm trying to render a template that contains a DatePicker, but I'm getting a 500 error when I try. For my the code is correct, but it seems that something is failing or I'm not understanding correctly the way to do it. The code is the…
Pepeluis
  • 931
  • 2
  • 10
  • 18
27
votes
2 answers

Add input fields dynamically with wtforms

I'm not quite sure how approach this matter. I hope i get there. For example I have a table full of addresses on a page. The count of these are dynamic (could be 5 or 10 or any other count). And I want the possibility to edit them on one page. My…
muthan
  • 2,342
  • 4
  • 20
  • 32
27
votes
4 answers

How do I validate wtforms fields against one another?

I have three identical SelectField inputs in a form, each with the same set of options. I can't use one multiple select. I want to make sure that the user selects three different choices for these three fields. In custom validation, it appears that…
YPCrumble
  • 26,610
  • 23
  • 107
  • 172
26
votes
4 answers

Python Flask SQLAlchemy Pagination

I am having trouble implementing pagination with Flask-SQLAlchemy or Flask-Pagination, either or. I am unsure how to initialize the pagination, setting pages, determining pages, offest, etc. I am coming from PHP, quite new to Python. I am querying…
user7731688
26
votes
3 answers

Pre-Populate a WTforms in flask, with data from a SQLAlchemy object

I am fairly new to flask framework and was creating an edit profile page for a webportal. I am stuck at a point and am unable to autofill a form. Here is my form class : class EditProfile(Form): username = TextField('Username', [Required()]) …
Hammad Haleem
  • 1,374
  • 1
  • 16
  • 26
25
votes
2 answers

populate WTForms select field using value selected from previous field

New to this, trying to build an app following a well known Flask tutorial, using Flask-bootstrap, Flask-wtforms, Jinja etc I have a form with 2 select fields and a button. class Form(FlaskForm): school_year = SelectField('School year',…
fkaralis
  • 445
  • 1
  • 6
  • 10
25
votes
2 answers

Using Flask-WTForms, how do I style my form section of the html?

I read through Flask-WTF extremely simplified wiki, and couldn't understand much about what I can do with it. I am under the impression that the
section of the html now can only look like {{ form.hidden_tag() }} …
return 0
  • 4,226
  • 6
  • 47
  • 72
25
votes
6 answers

Email Validation from WTForm using Flask

I'm following a Flask tutorial from http://code.tutsplus.com/tutorials/intro-to-flask-adding-a-contact-page--net-28982 and am currently stuck on the validation step: The old version had the following: from flask.ext.wtf import Form, TextField,…
lost9123193
  • 10,460
  • 26
  • 73
  • 113
1
2 3
99 100