flask-wtforms

Flask-WTF set time limit on CSRF token

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-19 03:49:46
问题 I'm currently using Flask-WTF v0.13.1, i have a few forms on my website, all created including the CSRF token. For some reasons i have to set a different expiration on each form, so far i could set manually the time_limit value upon creating the csrf token. I would like to update to the v0.14, according to the changelog time_limit is gone and there is no reference in the docs on how to change it anymore. Looking in the source code i saw that the form has a csrf_time_limit meta parameter. I

Flask WTF form not updating with the sqlite3 database

空扰寡人 提交于 2021-02-18 18:09:52
问题 I have a RadioField form item that uses values for its field from the database. If the database is not created I cannot start the Flask Webserver even though it should only access the database when I go to that page and load that form. If I update the database while the Webserver is running I don't see the form with the new database information. Until I restart the Flask webserver. How can I get it so that it forces the form to reload its values from the database when you visit the page. Also

Flask/WTForms/QuerySelectField - render QuerySelectField with a choice selected based on existing database value

孤街浪徒 提交于 2021-02-16 16:13:55
问题 I am building a simple CMS that includes a profile management page. On this profile page, along with other fields, there exists a dropdown list, which I generate from a table 'parks' using the wtforms extension's QuerySelectField: from wtforms.ext.sqlalchemy.fields import QuerySelectField The rest of the fields on the profile page are populated by the 'user' table. Let assume that a user has logged in, and that their record in the 'user' table is already populated. Among the fields in the

Flask-WTF FileField Uploaded file disappears after a couple days and doesn't show up in the folder

笑着哭i 提交于 2021-02-11 16:49:21
问题 So I'm just using the FileField to add files to the server and it worked the time I tested it on Heroku (by worked I mean the image was rendering properly, granted I should be using some more proper ways to render images), but after a couple days I checked again and the image is no longer rendering properly. I checked my uploads folder and the image is not there any longer (one of the old images were). I ran the test again and the image is showing but the picture file is not in the uploads

Check duplication when edit an exist database field with WTForms custom validator

心不动则不痛 提交于 2021-02-11 16:13:51
问题 I'm having this form with this validator for uniqueness: class CreateTypeForm(FlaskForm): type_name = StringField("Type", validators=[DataRequired()]) description = TextAreaField("Description") submit = SubmitField("Create") def validate_type_name(self, type_name): typeName = mongo.db.types.find_one({"type_name": type_name.data}) if typeName: raise ValidationError("The type already exists.") But need to alter the validator for the form I have when I edit my type : class EditTypeForm(FlaskForm

Check duplication when edit an exist database field with WTForms custom validator

烈酒焚心 提交于 2021-02-11 16:13:31
问题 I'm having this form with this validator for uniqueness: class CreateTypeForm(FlaskForm): type_name = StringField("Type", validators=[DataRequired()]) description = TextAreaField("Description") submit = SubmitField("Create") def validate_type_name(self, type_name): typeName = mongo.db.types.find_one({"type_name": type_name.data}) if typeName: raise ValidationError("The type already exists.") But need to alter the validator for the form I have when I edit my type : class EditTypeForm(FlaskForm

CSRF Protection with Flask/WTForms and React

☆樱花仙子☆ 提交于 2021-02-10 18:10:35
问题 Has anyone successfully implemented CSRF protection for a form submitted with React (as a controlled component) to a Flask back-end (ideally with WTForms)? I've seen a lot of partial answers, and one with Django, but couldn't find anything definitive for Flask. My big issue seems to be that I don't know how to send the csrf token to my react front end, store it as a header before submitting my form, then submit my form with the correct token. Any direction would be really helpful. 回答1: So,

wtforms SelectField with dynamic choices always returns “none” for data

穿精又带淫゛_ 提交于 2021-02-10 15:08:17
问题 I am new to wtforms. I have to provide user with list of fruits and cost of each fruit as shown below, Total number of fruits are dynamically generated and each fruit prices is also dynamically generated. Below is my declaration, from flask.ext.wtf import Form class SelectForm(Form): def __init__(self, csrf_enabled=False, *args, **kwargs): super(SelectForm, self).__init__(csrf_enabled=csrf_enabled, *args, **kwargs) fruits_list = wtforms.FieldList( wtforms.SelectField('fruits', validators =

wtforms SelectField with dynamic choices always returns “none” for data

爷,独闯天下 提交于 2021-02-10 15:02:21
问题 I am new to wtforms. I have to provide user with list of fruits and cost of each fruit as shown below, Total number of fruits are dynamically generated and each fruit prices is also dynamically generated. Below is my declaration, from flask.ext.wtf import Form class SelectForm(Form): def __init__(self, csrf_enabled=False, *args, **kwargs): super(SelectForm, self).__init__(csrf_enabled=csrf_enabled, *args, **kwargs) fruits_list = wtforms.FieldList( wtforms.SelectField('fruits', validators =

JQuery/AJAX call function seems to run only once and JQuery selector on AJAX result only yields the inner html

拈花ヽ惹草 提交于 2021-02-08 11:30:30
问题 I am new to programming and this is also my first question on this platform. I have tried implementing applicable solutions I could find here for similar questions raised but is still stuck. Should you believe that a previously answered question might answer mine, please share the link to such answer. Also please correct me should you find that I have broken some guidelines on how to properly ask questions on this platform. Now, on to the actual issues. The following are the relevant sections