flask-wtforms

Flask_form : CSRF Token do not match

二次信任 提交于 2020-05-15 04:23:07
问题 I'm using flask_form in my Flask application and have being stucked for hours now with the 'CSRF Token do not match'. <form method="post" action="{{ url_for('auth.login') }}" role="form"> {{ form.hidden_tag() }} {{ wtf.form_errors(form, hiddens="only") }} {{ wtf.form_field(form.email)}} {{ wtf.form_field(form.password)}} <p><button type="submit">Login</button></p> </form> views.py @auth.route('/login', methods=['GET', 'POST']) def login(): form = LoginForm() if form.validate_on_submit():

flask AttributeError: 'HTMLString' object has no attribute '__call__'

大城市里の小女人 提交于 2020-03-19 05:20:46
问题 I have created a macro to handle form errors as follows: {% macro render_field_with_errors(field) %} <p> {{ field.label }} {{ field(**kwargs)|safe }} {% if field.errors %} <ul> {% for error in field.errors %} <li style="color: red;">{{ error }}</li> {% endfor %} </ul> {% endif %} </p> {% endmacro %} {% macro render_field(field) %} <p>{{ field(**kwargs)|safe }}</p> {% endmacro %} My forms.py is as follows: from flask.ext.wtf import Form, TextField, BooleanField, PasswordField, RadioField,

Determine why WTForms form didn't validate

陌路散爱 提交于 2020-03-10 05:00:08
问题 I called form.validate_on_submit() , but it returned False . How can I find out why the form didn't validate? 回答1: For the whole form, form.errors contains a map of fields to lists of errors. If it is not empty, then the form did not validate. For an individual field, field.errors contains a list of errors for that field. The list is the same as the one in form.errors . form.validate() performs validation and populates errors . When using Flask-WTF, form.validate_on_submit() performs an

How to make Flask-WTF Validate Override execute properly

随声附和 提交于 2020-02-08 03:29:09
问题 I have created a simple form which contains a URLField and StringField . As shown below: from flask_wtf import Form from wtforms.fields import StringField from wtforms.fields.html5 import URLField #from flask.ext.wtf.html5 import URLField from wtforms.validators import DataRequired, url class BookmarkForm(Form): url = URLField('url') description = StringField('description') # override validate method of Form class for custom validation def validate(self): #app.logger.debug('Inside validate')

Wtforms form field text enlargement

限于喜欢 提交于 2020-02-02 10:56:28
问题 I am new to using wtforms and flask and am trying to enlarge the physical field size and the font inside of it. Should I use a specific piece of code or change it with css. <div class="container"> <div class="col-md-12"> <form id="signinform" class="form form-horizontal" method="post" role="form" style="font-size:24px;"> {{ form.hidden_tag() }} {{ wtf.form_errors(form, hiddens="only") }} {{ wtf.form_field(form.first_name, autofocus=true) }} {{ wtf.form_field(form.last_name) }} {{ wtf.form

Wtforms form field text enlargement

北战南征 提交于 2020-02-02 10:55:28
问题 I am new to using wtforms and flask and am trying to enlarge the physical field size and the font inside of it. Should I use a specific piece of code or change it with css. <div class="container"> <div class="col-md-12"> <form id="signinform" class="form form-horizontal" method="post" role="form" style="font-size:24px;"> {{ form.hidden_tag() }} {{ wtf.form_errors(form, hiddens="only") }} {{ wtf.form_field(form.first_name, autofocus=true) }} {{ wtf.form_field(form.last_name) }} {{ wtf.form

How to upload multiple files with flask-wtf?

杀马特。学长 韩版系。学妹 提交于 2020-02-02 04:31:17
问题 I am trying to upload multiple files with flask-wtf. I can upload a single file with no problems and I've been able to change the html tag to accept multiple files but as of yet I haven't been able to get more than the first file. The attached code will give me the first file but I can't figure out how to get any more files from it. I suspect that "render_kw={'multiple': True}" just changes the HTML tag so I might be barking up the wrong tree with this approach. I have also stumbled across

Append entry to FieldList with Flask-WTForms using AJAX

强颜欢笑 提交于 2020-02-01 03:52:11
问题 I made a simple form in Flask using Flask-WTForms where a parent can register itself and his children. The parent can register as many children as he wants, by clicking on the button 'Add child'. WTForms makes this pretty easy to implement by using the FieldList feature. However, after clicking on the button 'Add child' the page refreshes itself because it makes a request to the server. I want to use an AJAX request to add a child form, so the page doesn't refreshes itself. I know how to do

WTForms date validation

时光毁灭记忆、已成空白 提交于 2020-01-30 03:32:11
问题 I am currently trying to build a simple web application using Flask. With this i am also using WTForms, however i am having problem with getting date information from the form and getting it validated. This is the form: from flask_wtf import FlaskForm from wtforms import SubmitField from wtforms.fields.html5 import DateField from wtforms.validators import DataRequired from datetime import date class LeasForm(FlaskForm): start_date = DateField("Start date", default=date.today(), format='%d/%m/

Why is my flask form validation returning Not a valid choice?

拈花ヽ惹草 提交于 2020-01-30 03:20:29
问题 I have been trying to figure out why my Flask form will not properly validate my select field choices even though the choices are coming from the select field options. My assumption is that the select option when passed back from the server is unicode and is being compared to the choice which is a string, however, I thought coerce=str would fix that. I printed out the form data and request data which is the output below. Why isn't it working? My code is attached below, removed csrf token key