Questions tagged [wtforms]

WTForms is a flexible forms validation and rendering library for Python.

WTForms is a flexible forms validation and rendering library for Python.

Documentation: http://wtforms.readthedocs.io/en/latest/

Github: https://github.com/wtforms/wtforms/

Issue Tracker: https://github.com/wtforms/wtforms/issues

1497 questions
103
votes
17 answers

WTForms: Install 'email_validator' for email validation support

Getting exception when running the following code for form validation. File "/Users/homeduvvuri/Documents/Learning/PartyGoUdemy/PartGo/user/forms.py", line 11, in BaseUserForm email = EmailField('Email', [validators.DataRequired(),…
VeeDuvv
  • 1,131
  • 2
  • 5
  • 6
84
votes
4 answers

WTForms Can I add a placeholder attribute when I init a field?

I want to add a placeholder attribute on to the field in WTForms. How can I do it? abc = TextField('abc', validators=[Required(), Length(min=3, max=30)], placeholder="test") The above code is not valid How can I add a placeholder attribute with…
TheOneTeam
  • 25,806
  • 45
  • 116
  • 158
80
votes
5 answers

Add a css class to a field in wtform

I'm generating a dynamic form using wtforms (and flask). I'd like to add some custom css classes to the fields I'm generating, but so far I've been unable to do so. Using the answer I found here, I've attempted to use a custom widget to add this…
pheven
  • 949
  • 2
  • 8
  • 11
69
votes
9 answers

How do you set a default value for a WTForms SelectField?

When attempting to set the default value of a SelectField with WTForms, I pass in value to the 'default' parameter like so. class TestForm(Form): test_field = SelectField("Test: ", choices=[(1, "Abc"), (2, "Def")], default=2) I have also tried…
jan
  • 2,263
  • 5
  • 19
  • 22
55
votes
4 answers

Not a Valid Choice for Dynamic Select Field WTFORMS

I currently am creating a dynamic select field using WTFORMS, however it never submits and fails the validation with the following error. Not a valid choice My Field is created like this: area = SelectField() and in the view, i am grabbing the…
ismail
  • 3,882
  • 5
  • 36
  • 47
43
votes
9 answers

Flask-WTF - validate_on_submit() is never executed

I'm using Flask-WTF: Here is my form: from flask.ext.wtf import Form, TextField class BookNewForm(Form): name = TextField('Name') Here is the controller: @book.route('/book/new', methods=['GET', 'POST']) def customers_new(): form =…
kadrian
  • 4,761
  • 8
  • 39
  • 61
38
votes
5 answers

Recommendation for python form validation library

I would like a form validation library that 1.separate html generation from form validation; 2.validation errors can be easily serialized, eg. dumped as a json object What form validation library would you choose in a python web project?
satoru
  • 31,822
  • 31
  • 91
  • 141
35
votes
4 answers

How to make a field conditionally optional in WTForms?

My form validation is working nearly complete, I just have 2 cases I don't know exactly how to solve: 1) The password field should be required of course but I also provide the possibility to log in with google or facebook account via OAuth and then…
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
34
votes
4 answers

WTForms getting the errors

Currently in WTForms to access errors you have to loop through field errors like so: for error in form.username.errors: print error Since I'm building a rest application which uses no form views, I'm forced to check through all form fields…
Romeo M.
  • 3,218
  • 8
  • 35
  • 40
33
votes
4 answers

How to render my TextArea with WTForms?

To render my textareafield with a specified number of columns and rows with WTForms, how do I set the number of columns and rows? I followed the instructions from this question but it didn't work: How to specify rows and columns of a