wtforms

flask-wtforms. QuerySelectField RuntimeError

本小妞迷上赌 提交于 2020-07-23 06:38:21
问题 Im trying to use QuerySelectField in FlaskForm, but getting error. admin/forms.py class ServiceForm(FlaskForm): # def __init__(self, *args, **kwargs): # super(ServiceForm, self).__init__(*args, **kwargs) # self.category.choices = [(cat.id, cat.name) for cat in ServiceCategory.query.all()] category = QuerySelectField('Category', query_factory=ServiceCategory.query, get_pk=lambda a: a.id, get_label=lambda a: a.name) name = StringField('Name', validators=[DataRequired()]) description =

flask-wtforms. QuerySelectField RuntimeError

送分小仙女□ 提交于 2020-07-23 06:37:49
问题 Im trying to use QuerySelectField in FlaskForm, but getting error. admin/forms.py class ServiceForm(FlaskForm): # def __init__(self, *args, **kwargs): # super(ServiceForm, self).__init__(*args, **kwargs) # self.category.choices = [(cat.id, cat.name) for cat in ServiceCategory.query.all()] category = QuerySelectField('Category', query_factory=ServiceCategory.query, get_pk=lambda a: a.id, get_label=lambda a: a.name) name = StringField('Name', validators=[DataRequired()]) description =

How to add Bootstrap Validation to WTForms

泪湿孤枕 提交于 2020-07-19 16:42:41
问题 I am using WTForms in conjunction with Flask and I would like to integrate the Bootstrap Form Validation for errors in my form. I have a basic login form setup something like this: class LoginForm(FlaskForm): """Login form.""" email = EmailField( "Email Address", validators=[DataRequired(), Email(), Length(min=6, max=40)] ) password = PasswordField( "Password", validators=[DataRequired()] ) def __init__(self, *args, **kwargs): """Create instance.""" super(LoginForm, self).__init__(*args, *

How to add Bootstrap Validation to WTForms

纵然是瞬间 提交于 2020-07-19 16:38:51
问题 I am using WTForms in conjunction with Flask and I would like to integrate the Bootstrap Form Validation for errors in my form. I have a basic login form setup something like this: class LoginForm(FlaskForm): """Login form.""" email = EmailField( "Email Address", validators=[DataRequired(), Email(), Length(min=6, max=40)] ) password = PasswordField( "Password", validators=[DataRequired()] ) def __init__(self, *args, **kwargs): """Create instance.""" super(LoginForm, self).__init__(*args, *

How to add Bootstrap Validation to WTForms

南楼画角 提交于 2020-07-19 16:37:59
问题 I am using WTForms in conjunction with Flask and I would like to integrate the Bootstrap Form Validation for errors in my form. I have a basic login form setup something like this: class LoginForm(FlaskForm): """Login form.""" email = EmailField( "Email Address", validators=[DataRequired(), Email(), Length(min=6, max=40)] ) password = PasswordField( "Password", validators=[DataRequired()] ) def __init__(self, *args, **kwargs): """Create instance.""" super(LoginForm, self).__init__(*args, *

WTF form.validate_on_submit() not working

匆匆过客 提交于 2020-07-09 06:13:13
问题 I have the following code and I'm submitting a form. When I hit the submit button, my form validation prints out False . I've checked and made sure I'm including everything from different posts, but I can't get it to validate. Is there anything I'm doing wrong? @app.route('/index.html', methods=['GET', 'POST']) def index(): user = {'nickname': 'Rafa'} form = FilterForm() print("about to validate", file=sys.stderr) if form.validate_on_submit(): print("validated", file=sys.stderr) filters_array

WTForms form with custom validate method is never valid

谁说我不能喝 提交于 2020-07-09 02:36:13
问题 I want to get the data for a user input date, or the current date if nothing is entered. I used WTForms to create a form with a date input, and override validate to return True if the date field has data. However, the form is always invalid even if I enter a date. Why isn't this working? class ChooseDate(Form): date = DateField(format='%m-%d-%Y') def validate(self): if self.date.data is None: return False else: return True @app.route('/index', methods=['GET', 'POST']) def index(): date_option

WTForms: FieldList of FormField can't load nested data

北慕城南 提交于 2020-07-05 07:26:15
问题 I have a custom field inside a FormField inside a FieldList: locations class LocationForm(Form): id = HiddenField('id') title = StringField(_l('Title'), [Required()]) location = CoordinatesField(_l('Coordinates')) class ProjectForm(Form): title = StringField(_l('Title')) manager = StringField(_l('Manager')) description = StringField(_l('Description')) locations = FieldList(FormField(LocationForm), min_entries=1) This form when submited is saved to an object like this: document = { 'title':

Render an editable table using Flask, Jinja2 templates, then process the form data returned

强颜欢笑 提交于 2020-07-04 06:36:24
问题 I'm using Flask and Jinja2 and I need to make an editable table with multiple rows. This is what the table will look like: And here's HTML for that: <form action="/support/team-members-update" method="post"> <table> <tbody><tr> <th>Name</th> <th>Id</th> <th>Inbox Share</th> </tr> <tr> <td>Ben</td><td>55555</td><td><input type="text" name="share_55555" value="0"></td></tr> <tr> <td>Steve</td><td>66666</td><td><input type="text" name="share_66666" value="1"></td></tr> <tr> <td>Harry</td><td

Pass to and use a variable inside a FlaskForm (WTForms)

橙三吉。 提交于 2020-06-28 05:24:10
问题 The code is pretty self-explanatory - I want to pass a variable to a FlaskForm subclass for further use. from flask import Flask, render_template_string from flask_wtf import FlaskForm from wtforms import StringField from flask_wtf.csrf import CSRFProtect app = Flask(__name__) spam = 'bar' app.secret_key = 'secret' csrf = CSRFProtect(app) @app.route('/') def index(): eggs = spam form = FooForm(eggs) return render_template_string( ''' {{ form.bar_field.label }} {{ form.bar_field }} ''',form =