flask-wtforms

Get choices from a DataBase query in wtforms and flask-sqlalchemy

独自空忆成欢 提交于 2020-07-18 08:02:11
问题 I'm developing a web app using Flask, SQLAlchemy and WTForms. I would like to get my choices in a SelectField from a query through my DB. With more details. my_query = my_table.query.with_entities(My_Entities).all() Result [(u'1',), (u'2',), (u'3',)] My class class MyForm(Form): My_Var = SelectField(choices=RIGHT_HERE) Is there any way ? 回答1: In this situation what you can do is use the extensions that are in WTForms. What you do is import the QuerySelectField that you need: from wtforms.ext

WTF form.validate_on_submit() not working

匆匆过客 提交于 2020-07-09 06:13:13
问题 I have the following code and I'm submitting a form. When I hit the submit button, my form validation prints out False . I've checked and made sure I'm including everything from different posts, but I can't get it to validate. Is there anything I'm doing wrong? @app.route('/index.html', methods=['GET', 'POST']) def index(): user = {'nickname': 'Rafa'} form = FilterForm() print("about to validate", file=sys.stderr) if form.validate_on_submit(): print("validated", file=sys.stderr) filters_array

WTForms Regexp validator: How to match white space within html tags using regex

☆樱花仙子☆ 提交于 2020-06-28 03:57:33
问题 I have a form with a textarea field and wonder if I could use WTForms Regexp validator to prevent the form submitting when the textarea contains only blank spaces. Is there a way? This is my form: class AddReviewForm(FlaskForm): review = TextAreaField("Review", validators=[DataRequired()) submit = SubmitField("Post Review") I was hoping Regexp would allow me to prevent only spaces. My textarea fields include CKEditor , which adds <p> (or other tags) to the input in order to display it as

'CSRF Token is missing' in Flask but it *is* rendering in the template

元气小坏坏 提交于 2020-06-28 03:41:20
问题 The Problem When I try to login (using Flask-login) I get Bad Request The CSRF session token is missing but the token is rendering (in the template), secret_key is set, and I'm running locally at localhost:5000 . When I was able to log in, I could no longer use my Flask-WTF forms for the same reason. By calling form.validate() on the route, I got CSRF token missing for all of the forms. Effectively the forms just did nothing. If I look in the template where I call {{form.hidden_tag()}} the

WTForms TextAreaField DataRequired not raising validation error in Bootstrap modal

妖精的绣舞 提交于 2020-06-09 04:21:22
问题 I have a very small form in a bootstrap modal including just two fields: a TextAreaField and a Submit button. My TextAreField is DataRequired . On top of that this field uses CKEditor (similar to quillsJS) to make the text area WYSIWYG. Problem is that the form submits even when no data has been entered, and reloads the parent page. I would very much like to know how to prevent that form submission and raise the validation error when no data has been entered. I would like to get WTForm

WTForms TextAreaField DataRequired not raising validation error in Bootstrap modal

て烟熏妆下的殇ゞ 提交于 2020-06-09 04:21:12
问题 I have a very small form in a bootstrap modal including just two fields: a TextAreaField and a Submit button. My TextAreField is DataRequired . On top of that this field uses CKEditor (similar to quillsJS) to make the text area WYSIWYG. Problem is that the form submits even when no data has been entered, and reloads the parent page. I would very much like to know how to prevent that form submission and raise the validation error when no data has been entered. I would like to get WTForm

WTForms TextAreaField DataRequired not raising validation error in Bootstrap modal

流过昼夜 提交于 2020-06-09 04:21:08
问题 I have a very small form in a bootstrap modal including just two fields: a TextAreaField and a Submit button. My TextAreField is DataRequired . On top of that this field uses CKEditor (similar to quillsJS) to make the text area WYSIWYG. Problem is that the form submits even when no data has been entered, and reloads the parent page. I would very much like to know how to prevent that form submission and raise the validation error when no data has been entered. I would like to get WTForm

FlaskWTF same form on every view / page

吃可爱长大的小学妹 提交于 2020-06-01 05:09:26
问题 in my Flask Project i have configured a basepage.html Jinja template every other page inherits from. In this basepage.html i want to have a Search bar at the top, so that it also appears at every page inheriting from it. The input from this search form (is a form even the best way to do it?) should be processed by the routing function search() I defined as follows: views.py @app.route('/') @app.route('/dashboard') def dashboard(): return render_template('Dashboard.html') #Dashboard.html

How do I bind an flask-wtform UnboundField?

老子叫甜甜 提交于 2020-05-30 19:16:54
问题 I am creating an app to post products to a marketplace. Each product category on this marketplace has a different form for product attributes, for example if it's electronic there are fields for voltage, model number... I get this information via json through the marketplace server. First the user has to write the name of the product and it's main category and the marketplace server predicts their own category and returns to me it's attributes. Here's an example of the response: { "id":

How do I bind an flask-wtform UnboundField?

无人久伴 提交于 2020-05-30 19:15:53
问题 I am creating an app to post products to a marketplace. Each product category on this marketplace has a different form for product attributes, for example if it's electronic there are fields for voltage, model number... I get this information via json through the marketplace server. First the user has to write the name of the product and it's main category and the marketplace server predicts their own category and returns to me it's attributes. Here's an example of the response: { "id":