flask-wtforms

Pre-Populate a WTforms in flask, with data from a SQLAlchemy object

馋奶兔 提交于 2019-11-27 00:56:57
问题 I am fairly new to flask framework and was creating an edit profile page for a webportal. I am stuck at a point and am unable to autofill a form. Here is my form class : class EditProfile(Form): username = TextField('Username', [Required()]) email = TextField('Email', [Required()]) about = TextAreaField('About', [Required()]) website = TextField('Website', [Required()]) This is my function that evaluates the form. def editprofile(nickname = None): if g.fas_user['username'] == nickname or

Flask view shows 400 error instead of template with form

耗尽温柔 提交于 2019-11-26 23:19:45
I'm trying to display a page with a form, then add a Player to the database when the form is submitted. However, I can't view the form because the browser always shows a 400 Bad Request error. Other posts indicate that this could be because the name of the form input doesn't match the key I get from request.form , but all my keys match. Why do I get this error? <form method="post"> {{ form.hidden_tag() }} <input name="name"> <input name="available"> <input type="submit"> </form> @app.route('/addplayer', methods=['GET', 'POST']) def addplayer(): connect('basketball_contracts', host='localhost',

Why does Flask WTForms and WTForms-SQLAlchemy QuerySelectField produce too many values to unpack?

回眸只為那壹抹淺笑 提交于 2019-11-26 21:43:41
问题 I've got a pretty basic Flask app: from flask import Flask, render_template from flask_wtf import FlaskForm from wtforms_sqlalchemy.fields import QuerySelectField from wtforms.validators import DataRequired from flask_sqlalchemy import SQLAlchemy from wtforms import StringField db = SQLAlchemy() app = Flask(__name__) app.config['SQLALCHEMY_URI'] = 'sqlite:///:memory:' app.config['SECRET_KEY'] = 'fnord' db.init_app(app) class Section(db.Model): id = db.Column(db.Integer, primary_key = True)

how to use QuerySelectField in flask?

為{幸葍}努か 提交于 2019-11-26 21:22:33
问题 I am trying to have a select field filled with the results of a sqlalchemy request in a flask form. Here are the code : def possible_book(): return Book.query.with_entities(Book.id).all() class AuthorForm(Form): familyname = TextField('familyname', [validators.Required()]) firstname = TextField('firstname', [validators.Required()]) book_list = QuerySelectField('book_list',query_factory=possible_book,get_label='title',allow_blank=True) This is the template : <form action="" method="post" name=

AJax does not work with bootstrap-select

可紊 提交于 2019-11-26 20:38:39
问题 I found flask-jquery-ajax example where the user selects an item from the vehicle "Make" drop down menu, the vehicle "Model" drop down menu is populated by making an AJAX request for a list of models for the make selected. I tried to replace the drop-down menus by bootstrap-select and as soon as I include class="selectpicker form-control" in the second drop-down menu it does not get any more populated after the first drop-down has been chosen. This is the HTML template: <!DOCTYPE html> <html

Add input fields dynamically with wtforms

你说的曾经没有我的故事 提交于 2019-11-26 19:17:14
问题 I'm not quite sure how approach this matter. I hope i get there. For example I have a table full of addresses on a page. The count of these are dynamic (could be 5 or 10 or any other count). And I want the possibility to edit them on one page. My approach was to create a Form with wtforms to edit one address and to multiply it in a jinja2 for loop and append to the html propertys name and id the loop.index0 from the itereation, so i can extract each row of data manually and put it back in my

Determine which WTForms button was pressed in a Flask view

心已入冬 提交于 2019-11-26 16:48:23
问题 I have a page with multiple links to redirect the user to different pages. I thought using a form would be nicer, so I defined a WTForms Form with multiple SubmitFields . How do I determine which button was clicked and redirect based on that? class MainForm(Form): user_stats = SubmitField('User Stats') room_stats = SubmitField('Room Stats') @main.route('/') @login_required def index(): form = MainForm() return render_template('index.html', form=form) <form action="#" method="post"> {{ wtf

flask-wtforms field required

谁说胖子不能爱 提交于 2019-11-26 14:52:07
问题 how i can add tag required on this flask code : {{ form.youtube_href(type='url', class='form-control') }} actual output is : <input class="form-control" id="youtube_href" name="youtube_href" value="" type="url"> need this output bat give error : <input class="form-control" id="youtube_href" name="youtube_href" value="" type="url" required> im tried this bat give error : {{ form.youtube_href(type='url', class='form-control', 'required') }} 回答1: As of WTForms 2.2 (June 2nd, 2018), fields now

Clear valid form after it is submitted

流过昼夜 提交于 2019-11-26 12:47:16
问题 I want to reset the form after it validates. Currently the form will still show the previous data after it is submitted and valid. Basically, I want the form to go back to the original state with all fields clean. What is the correct to do this? @mod.route(\'/\', methods=[\'GET\', \'POST\']) def home(): form = NewRegistration() if form.validate_on_submit(): #save in db flash(gettext(u\'Thanks for the registration.\')) return render_template(\"users/registration.html\", form=form) 回答1: The

Dynamic choices WTForms Flask SelectField

我怕爱的太早我们不能终老 提交于 2019-11-26 11:31:48
问题 I\'m trying to pass userID variable to WTForms with FlaskForms. First I\'ll show code that works fine and then what I need to modify(that the part I don\'t know how). I\'m adding new Name associated with some group. FlaskForm model: class AddName(FlaskForm): name =StringField(\'Device name\', validators=[InputRequired(),Length(min=4, max=30)]) groupID = SelectField(\'Payload Type\', choices=[(1,\"Group1\"),(2,\"Group2\")], validators=[InputRequired]) View model: @app.route(\'/dashboard