flask-wtforms

flask-bootstrap with two forms in one page

假装没事ソ 提交于 2019-12-01 00:13:10
I plan to put two forms in one page in my flask app, one to edit general user information and the other to reset password. The template looks like this {% extends "base.html" %} {% import "bootstrap/wtf.html" as wtf %} {% block page_content %} <div class="page-header"> <h1>Edit Profile</h1> </div> {{ wtf.quick_form(form_profile, form_type='horizontal') }} <hr> {{ wtf.quick_form(form_reset, form_type='horizontal') }} <hr> {% endblock %} Each form has a submit button. In the route function, I tried to separate the two form like this form_profile = ProfileForm() form_reset = ResetForm() if form

flask-bootstrap with two forms in one page

喜夏-厌秋 提交于 2019-11-30 18:27:55
问题 I plan to put two forms in one page in my flask app, one to edit general user information and the other to reset password. The template looks like this {% extends "base.html" %} {% import "bootstrap/wtf.html" as wtf %} {% block page_content %} <div class="page-header"> <h1>Edit Profile</h1> </div> {{ wtf.quick_form(form_profile, form_type='horizontal') }} <hr> {{ wtf.quick_form(form_reset, form_type='horizontal') }} <hr> {% endblock %} Each form has a submit button. In the route function, I

How do I validate wtforms fields against one another?

做~自己de王妃 提交于 2019-11-30 17:19:41
I have three identical SelectField inputs in a form, each with the same set of options. I can't use one multiple select. I want to make sure that the user selects three different choices for these three fields. In custom validation, it appears that you can only reference one field at a time, not compare the value of this field to others. How can I do that? Thanks! You can override validate in your Form ... class MyForm(Form): select1 = SelectField('Select 1', ...) select2 = SelectField('Select 2', ...) select3 = SelectField('Select 3', ...) def validate(self): if not Form.validate(self):

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

心已入冬 提交于 2019-11-30 13:59:59
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 . pjcunningham validate_on_submit() is a shortcut for is_submitted() and validate() . From the source code , line 89, is_submitted() returns True if the form submitted is an active request and the method is POST, PUT, PATCH, or DELETE.

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

て烟熏妆下的殇ゞ 提交于 2019-11-30 11:17:14
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 being returned ? Also the ID field I'm using is pulled from GAE's ndb automatic key().id() which is

Dynamic Forms (Formsets) in Flask / WTForms?

ぐ巨炮叔叔 提交于 2019-11-30 07:32:53
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="checkbox" id="{{request.key.urlsafe()}}" name="checkbox{{loop.index}}"> </td> </tr> {% endfor %} </tbody

Creating flask form with selects from more than one table

随声附和 提交于 2019-11-30 05:31:52
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. I tried to find a explanation for how to do this and couldn't find one. So I'm going to write one here. This is how I do

DatePickerWidget with Flask, Flask-Admin and WTforms

蹲街弑〆低调 提交于 2019-11-29 21:53:37
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('Start', validators=[Required()], format = '%d/%m/%Y', description = 'Time that the event will occur',

How to send query results to a WTForm Field?

做~自己de王妃 提交于 2019-11-29 17:46:38
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 class Post(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(80)) body =

Validate WTForm form based on clicked button

百般思念 提交于 2019-11-29 08:48:22
On my form, I have two buttons that I use for submitting the form. One button deletes selected files (presented in a table, one checkbox to an object) and the other selects them for processing. When the files are selected on deletion, no validation is necessary (beyond checking that at least one file has been selected). However, for processing I need to make sure that there is exactly one file of a certain extension. Basically, I need different validation processes based on which button the user clicked. How can I best do this? I know I can perform validation in the view, but I would much