flask-wtforms

WTForms: IntegerField skips coercion when string value is '0'

风格不统一 提交于 2019-12-20 02:43:20
问题 This question almost covers what I am after here, but not quite. It seems like IntegerField skips coercion when the string value is '0'. Any other positive integer seems to work okay. Here is an example of '0': from wtforms import validators, Form, IntegerField from webob.multidict import MultiDict class TestForm(Form): num = IntegerField('How Many?', [validators.DataRequired('num required.'), validators.NumberRange(min=0, max=100)]) data_in = {'num': '0'} # Note '0' is a string as would be

Flask WTForms: Why is my POST request to upload a file not sending the file data?

ⅰ亾dé卋堺 提交于 2019-12-19 08:12:57
问题 I am trying to make a form to upload a file, but the file data is not being sent with the request. I'm manually navigating to my file and hitting submit. My FileRequired validator fails. (And if I don't include it the data field on form.scan_file is empty.) Here's my form: from flask_wtf import FlaskForm from flask_wtf.file import FileField, FileAllowed, FileRequired class ScanForm(FlaskForm): scan_file = FileField(validators=[FileAllowed(['nii', 'nii.gz', 'zip']), FileRequired()]) Here's my

WTForms creating a custom widget

我与影子孤独终老i 提交于 2019-12-19 05:58:23
问题 The WTForms documentation is woefully inadequate, they don't even show you one single example of a custom widget that isn't derived from another widget already. I am trying to make a button type, that isn't an <input> in html: submit = InlineButton(name='submit', type='submit', title='Save this page', textWithinSpan='Save') This is what I'm trying: from flask.ext.wtf import Required, Length, EqualTo, Field, TextInput, html_params from flask import Markup class InlineButtonWidget(object): text

Difference between `form.validate_on_submit()` and `form.validate()`

此生再无相见时 提交于 2019-12-18 15:50:21
问题 What is the difference between form.validate_on_submit() and form.validate() ? In the Flask WTF docs, the author uses form.validate_on_submit() . The code works. When I substitute form.validate_on_submit() with form.validate() , I see no difference in behavior. I couldn't find form.validate_on_submit() in the source, but I managed to find form.validate() code. 回答1: validate_on_submit() is a shortcut for is_submitted() and validate() . From the source code, line 89, is_submitted() returns True

Difference between `form.validate_on_submit()` and `form.validate()`

大憨熊 提交于 2019-12-18 15:49:57
问题 What is the difference between form.validate_on_submit() and form.validate() ? In the Flask WTF docs, the author uses form.validate_on_submit() . The code works. When I substitute form.validate_on_submit() with form.validate() , I see no difference in behavior. I couldn't find form.validate_on_submit() in the source, but I managed to find form.validate() code. 回答1: validate_on_submit() is a shortcut for is_submitted() and validate() . From the source code, line 89, is_submitted() returns True

I'm having problems with wtforms selectfields when i use a POST with Flask

穿精又带淫゛_ 提交于 2019-12-18 14:07:32
问题 I'm pretty new to wtforms and flask and was messing around with selectfields and got an error. The form itself works just fine without the selectfield but with it I get the following error: Error: ....fields.py", line 386, in pre_validate for v, _ in self.choices: TypeError: 'NoneType' object is not iterable I see the selectfield so it's being rendered. I suspect somehow the id is not being validated properly on POST and is returning none. Or it has something to do with my selectfield tuple

Dynamic Forms (Formsets) in Flask / WTForms?

与世无争的帅哥 提交于 2019-12-18 12:37:21
问题 In Django you have a multiple form feature called Formsets, which you can use to create multiple forms into the same template. I am trying to achieve something similar in Flask / WTforms. <form action="{{ url_for('request-accept') }}" method='post'> <table> <tbody> {% for request in requests %} <tr> <td> <div class="person-header"> <img src="{{request.profile_pic_url}}" class="img-circle profile-image"/> <p class="person-header-text">{{request.fullname()}}</p> </div> </td> <td> <input type=

Flask WTForms: Difference between DataRequired and InputRequired

南楼画角 提交于 2019-12-18 03:54:35
问题 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? 回答1: Short Answer Unless you have a good reason you should use InputRequired Why? Lets look at some notes from the docs/code: Note there is a distinction between this and DataRequired in that InputRequired looks that form-input data was provided, and DataRequired

Flask WTForms: Difference between DataRequired and InputRequired

假装没事ソ 提交于 2019-12-18 03:54:35
问题 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? 回答1: Short Answer Unless you have a good reason you should use InputRequired Why? Lets look at some notes from the docs/code: Note there is a distinction between this and DataRequired in that InputRequired looks that form-input data was provided, and DataRequired

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

狂风中的少年 提交于 2019-12-18 03:38:29
问题 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 <form> section of the html now can only look like <form method="post"> {{ form.hidden_tag() }} {{ form.name }} <input type="submit"> </form> But I really want to style my using materialized such as: <div class="row"> <div class="input-field col s6"> <i class="material-icons prefix">account_circle</i> <input value="FN" id="first_name" type="text"