wtforms

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

wtforms hidden field value

你离开我真会死。 提交于 2019-11-30 08:48:11
I am using WTForms, and I have a problem with hidden fields not returning values, whereas the docs say they should. Here's a simple example: forms.py: from wtforms import (Form, TextField, HiddenField) class TestForm(Form): fld1 = HiddenField("Field 1") fld2 = TextField("Field 2") experiment.html: {% from "_formshelper.html" import render_field %} <html> <body> <table> <form method=post action="/exp"> {% for field in form %} {{ render_field(field) }} {% endfor %} <input type=submit value="Post"> </form> </table> </body> </html> (render_field just puts the label, field and errors in td tags)

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

WTForms-How to prepopulate a textarea field?

℡╲_俬逩灬. 提交于 2019-11-30 06:29:10
Hi I have been trying to pepopulate a textareafield using something like this in the template. {{form.content(value="please type content")}} This works when the field is textfield primarily because the html accepts value for <input type="text"> but the same does not work for textarea... Can someone please help me with this? For textarea widgets, you set the default content with the default argument in your field constructors. class YourForm(Form): your_text_area = TextAreaField("TextArea", default="please add content") Then when you render: {{form.content()}} WTForms will render the default

wtforms+flask today's date as a default value

可紊 提交于 2019-11-30 02:44:44
问题 I did a small Flask app with a form with two date fields, and this is how I populate the values: class BoringForm(Form): until = DateTimeField("Until", format="%Y-%m-%dT%H:%M:%S", default=datetime.today(), validators=[validators.DataRequired()]) However, this is generated only once, server-side, which means that tomorrow I'll still get yesterday's date. I tried passing obj=something to the constructor, where something was an OrderedDict with a key called since , but it didn't work. Ideas? 回答1

WTForms: How to select options in SelectMultipleField?

匆匆过客 提交于 2019-11-30 01:58:48
Choices can be set using form.myfield.choices=[("1","Choice1"), ("2","Choice2")] What is the way to set the selected option? You can use the choices and default keyword arguments when creating the field, like this: my_choices = [('1', 'Choice1'), ('2', 'Choice2'), ('3', 'Choice3')] SelectMultipleField(choices = my_choices, default = ['1', '3']) This will mark choices 1 and 3 as selected. Edit: Default values are apparently processed (copied into the data member) when the form is instatiated, so changing the default afterwards won't have any effect, unless you manually call process() on the

Wtforms, add a class to a form dynamically

守給你的承諾、 提交于 2019-11-30 01:52:51
is there a way i could send a form's (css) class from python? For example: class Company(Form): companyName = TextField('Company Name', [validators.Length(min=3, max = 60)]) This renders a simple text field, but i want that text field to have the css class of .companyName , is that possible directly from python? I know that i can put a id="companyName" directly from python, but not class. Help. Update: I tried class_="companyName" and it did not work, i got: __init__() got an unexpected keyword argument '_class' WTForms does not allow you to set display options (such as class name) in the

Unique validator in WTForms with SQLAlchemy models

独自空忆成欢 提交于 2019-11-30 00:33:16
I defined some WTForms forms in an application that uses SQLALchemy to manage database operations. For example, a form for managing Categories: class CategoryForm(Form): name = TextField(u'name', [validators.Required()]) And here's the corresponding SQLAlchemy model: class Category(Base): __tablename__= 'category' id = Column(Integer, primary_key=True) name = Column(Unicode(255)) def __repr__(self): return '<Category %i>'% self.id def __unicode__(self): return self.name I would like to add a unique constraint on the form validation (not on the model itself). Reading the WTForms documentation ,

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',

Recommendation for python form validation library [closed]

筅森魡賤 提交于 2019-11-29 20:36:11
I would like a form validation library that 1.separate html generation from form validation; 2.validation errors can be easily serialized, eg. dumped as a json object What form validation library would you choose in a python web project? Y.H Wong Disclaimer Generally speaking I'm a little wary about HTML form libraries now. If you use something from a mega-framework, you invariably have to bring in the whole mega-framework as your dependency. Many sub-components of many mega-frameworks claim to not depend on the framework but let's not kid ourselves. If you don't use one, there are at least a