flask-wtforms

flask wtforms QuerySelectFeld form.populate_obj fields not populated and if filled in error translate raised

偶尔善良 提交于 2021-01-29 11:41:52
问题 I am struggling with two problems, 1/ QuerySelectField not populated 2/ Translate error if field is filled in I have an add function and an edit function, I am using "from wtforms_alchemy.fields import QuerySelectField" to allow a choice from one data base model to be available in a drop down list. In the "addboilercircuit" function this works, in the form a drop down list is displayed and I can submit the form. in the "editboilercircuit" function I am using formpopulate_obj all the fields

Flask WTF forms: can a new field be shown if a user selects a specific choice in SelectMultipleField?

断了今生、忘了曾经 提交于 2021-01-28 19:16:17
问题 I just started using Flask WTF forms. I can do everything that I need with them except I can't seem to figure out one thing. I have a multiple choice field presenting various options to the user, and if the user selects "other", I want them to describe what they mean. Like this: impact = wtforms.SelectMultipleField('What is the expected impact?', choices=[('Sales', 'Sales'), ('Lift', 'Lift'), ('Other', 'Other')] I don't know if it's even possible when it's not an independent field with its

FileAllowed does not display an error message

余生长醉 提交于 2021-01-28 05:09:09
问题 I am using WTForms. I am applying validation on file upload and restricted it to jpg,png and pdf format only. however if i give an incorrect input, no error message appears. I followed this tutorial https://flask-wtf.readthedocs.io/en/stable/form.html photo = FileField('photo', validators=[ FileRequired(), FileAllowed(['png', 'pdf', 'jpg'], "wrong format!") ]) 回答1: By default, flask-wtf does not show any error message if validation fails. Error messages can be caught and shown for each

Jinja: loop to create form fields with same name but the last character

随声附和 提交于 2021-01-28 03:30:25
问题 I am using Flask and I have a WTF form with 12 input fields named like sold_1, sold_2,..., sold_12. I would like to generate these fields in Jinja using a loop like: {% for r in range(1, 13) %} {{ form.sold_ }}{{ r }} {% endfor %} or a similar syntax, but it doesn't work. I solved it in a quite convoluted way as follows: {% set tmp = "sold_x" %} {% for r in range(1, 13) %} {{ form[tmp | replace('x', r)] }} {% endfor %} but I wonder whether there is a cleaner way. Thanks 回答1: You could use

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

天大地大妈咪最大 提交于 2021-01-20 17:48:26
问题 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 Flask, render_template, request from firebase import firebase from flask_wtf import FlaskForm from flask_wtf.csrf import CSRFProtect, CSRFError from wtforms import DateField, StringField, TextAreaField from wtforms.validators import DataRequired from