flask-wtforms

Creating flask form with selects from more than one table

自古美人都是妖i 提交于 2019-11-29 05:42:21
问题 I have seen a large number of tutorials that show login forms with flask and flash-wtf but none where multiple select boxes are populated from database table values. This is what I am trying to do: A simple registration form: First name Last name Address Line 1 Address Line 2 City State Id (populated from states library query of Id,state) Country Id (populated from countries library query of country, id) Sample code or a link to a walk through would be greatly appreciated. 回答1: I tried to

WTForm: FieldList with SelectField, how do I render?

左心房为你撑大大i 提交于 2019-11-29 03:20:58
问题 I have this order form which allows my users to create an order. An order consists of multiple tuples of (producetype, quantity) . Producetype should be rendered in a <select> form while quantity can just be an input. The choices of producetype should be dynamically added because that could change. Currently, I've written this in bare html I would like to use WTForm for this because WTForm really simplifies my code. However, I am unable to do so: Code: class OrderEntryForm(Form): quantity =

Dynamic select field using WTForms not updating

妖精的绣舞 提交于 2019-11-28 22:10:52
I'm trying to make a dynamic select field using wtforms and sqlalchemy, but it doesn't update when an item is inserted or deleted from the database. Here's my code: class UserForm(Form): username = StringField('Username', validators=[DataRequired()]) password = PasswordField('Password', validators=[DataRequired()]) job = SelectField( 'Job', validators=[DataRequired()], choices=[(a.id, a.name) for a in Job.query.order_by(Job.name)] ) And the database model: class Job(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String) def __init__(self, name):

How to use WTForms in Ajax validation?

风格不统一 提交于 2019-11-28 18:24:37
I accustomed of using WTForms by means of Flask-WTF in my flask application. Doing server side validation is trivial. But how do I leverage this server validation to become a field level, ajax, client side validation? So, when user tab to another input fields, my application can directly goes on validating it and give validation warning/info/error. I haven't found a resource in the internet yet A possible solution is as follows: On the client side you attach a handler to the blur event in all the controls in the form. Each time the blur event occurs you run a Javascript function that collects

DatePickerWidget with Flask, Flask-Admin and WTforms

邮差的信 提交于 2019-11-28 17:54:25
问题 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 following: Reporting.py from flask.ext.admin import BaseView, expose from wtforms import DateField, Form from wtforms.validators import Required from flask.ext.admin.form import widgets from flask import request class DateRangeForm(Form): start_date = DateField

Filling WTForms FormField FieldList with data results in HTML in fields

江枫思渺然 提交于 2019-11-28 17:17:37
I have a Flask app in which I can populate form data by uploading a CSV file which is then read. I want to populate a FieldList with the data read from the CSV. However, when I try to populate the data, it enters raw HTML into the TextFields instead of just the value that I want. What am I doing wrong? app.py from flask import Flask, render_template, request, url_for from flask.ext.wtf import Form from wtforms import StringField, FieldList, FormField, SelectField from wtforms.validators import DataRequired from werkzeug.datastructures import MultiDict app = Flask(__name__) app.config['SECRET

How to populate wtform select field using mongokit/pymongo?

大城市里の小女人 提交于 2019-11-28 13:05:41
I'm trying to create a SelectField using a mongodb query, but so far I haven't been successful: # forms.py in blueprint CATEGORIES = [] for item in db.Terms.find(): CATEGORIES.append((item['slug'], item['name'])) class TermForm(Form): category = SelectField( choices=CATEGORIES, validators=[Optional()]) But I get an exception: Traceback (most recent call last): File "/home/one/Projects/proj/manage.py", line 14, in <module> app = create_app(os.getenv('FLASK_CONFIG') or 'default') File "/home/one/Projects/proj/app/__init__.py", line 27, in create_app from app.term.models import Term, TermCategory

How to send query results to a WTForm Field?

为君一笑 提交于 2019-11-28 11:43:13
问题 I use SQLalchemy with a many to many table to manage blog post tags. I need help rendering the tag values into a TextArea form field where they can be edited. Right now when I render I see the lookup query. Model The relationship between Tag and Post is is defined in `tags' class Tag(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50), unique=True) url = db.Column(db.String(120), unique=True) def __init__(self, name, url): self.name = name self.url = url

Why does a Flask app create two process? [duplicate]

老子叫甜甜 提交于 2019-11-28 11:11:23
This question already has an answer here: Why does running the Flask dev server run itself twice? 4 answers As far as I understood Flask should create a thread and a second thread to run on it, but what I see is there are always two processes, not threads, running. Even for the simplest app. from flask import Flask from flask import render_template, request, flash, session, redirect app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello World!' app.run(host="192.168.21.73", port=5000, debug=True) You can see two process running: ps -x 5026 ttyO0 S+ 0:01 /usr/bin/python ./test

wtforms, CSRF, flask, FieldList

社会主义新天地 提交于 2019-11-28 10:54:52
I'm having trouble passing through validation when using a FieldList with WTForms. I keep getting this error. {'csrf_token': [u'CSRF token missing']} . The problem is if I do not have any data to validate in the FieldList field, the validation passes and there are no issues. But when I try to validate the form with any data I get that error. Here are my forms: class FilterForm(wtf.Form): filter_value = wtf.TextField('Value', validators=[validators.Required()]) filter_operator = wtf.SelectField('Operator', validators=[validators.Required()]) filter_compare_value=wtf.TextField('Compare Value',