flask-wtforms

python wtf AttributeError: 'ObjectIdField' object has no attribute 'help_text'

安稳与你 提交于 2019-12-12 09:14:55
问题 Based on this tutorial I am trying to create a form to get a few measurements. It seems that the part to display the data is working but when using the model_form command to generate the input form it breaks with this error: File "/myproject/lib/python3.4/site-packages/flask_mongoengine/wtf/orm.py", line 49, in convert 'description': field.help_text or '', AttributeError: 'ObjectIdField' object has no attribute 'help_text' The error happens on this line of my code: form_cls = model_form

Multiple instances of the same form field

倖福魔咒の 提交于 2019-12-12 08:09:39
问题 I have invite form with two fields defined as person and email as follows: class InviteForm(Form): person = TextField("person", validators=[validators.Required("Please enter persons name.")]) email = EmailField("email", validators=[validators.Required("Please enter valid email."), validators.Email("Please enter valid email.")]) def validate(self): return validate_form(self) Where validate_form function is a cusotm validator which check few conditions for invite. My requirement is to allow

How can I import Flask-WTF?

眉间皱痕 提交于 2019-12-12 05:49:35
问题 I recently installed Flask-WTF and wtforms and wtf, using pip. I just don't know how to import anyone of these in my python file __init__.py . I tried: from wtforms import Form from Flask_WTF import Form from wtf import Form from flask_wtf import Form from flask_wtforms import Form etc... Most of the Flask Documentations tell me to use from wtforms import Form ... But it shows ImportError: No module named wtforms . It seems like the way you have to import WTF (or however it is called) is not

how to stack Vertically or Horizontally two MultiCheckboxField wtform fields

早过忘川 提交于 2019-12-12 05:29:11
问题 i have a form that uses a widget. what i want is two vertical columns side by side with the checkboxes. class MultiCheckboxField(SelectMultipleField): widget = widgets.ListWidget(prefix_label=False) option_widget = widgets.CheckboxInput() class SimpleForm2(Form): menu_items = MultiCheckboxField('Menu Item', choices=[], coerce=int) contents = MultiCheckboxField('Content', choices=[], coerce=int) submit = SubmitField('OK') for example Menu Item | Content cbox1 | cbox1' 回答1: This is a Horizontal

Wtfforms dynamic generation

陌路散爱 提交于 2019-12-12 05:25:10
问题 I have two wtfforms class SportStartForm(Form): ski = DateField(format='%d.%m.%Y') kitesurfing = DateField(format='%d.%m.%Y') windsurfing = DateField(format='%d.%m.%Y') surfing = DateField(format='%d.%m.%Y') class UpdateUserForm(Form): sport_start_at = FormField(SportStartForm) It works fine, but I want generate one of this form dynamically class SportStartForm(Form): def __new__(cls, **kwargs): for s in SPORTS: setattr(cls, s, DateField(format='%d.%m.%Y')) return super(SportStartForm, cls)._

Flask AttributeError: 'unicode' object has no attribute 'tell'

三世轮回 提交于 2019-12-11 23:36:20
问题 I'm trying to upload images to Amazon S3 with a Flask app and store the keys and metadata in a Redis db. Here is my app: def s3upload(image, acl='public-read'): key = app.config['S3_KEY'] secret = app.config['S3_SECRET'] bucket = app.config['S3_BUCKET'] conn = S3Connection(key, secret) mybucket = conn.get_bucket(bucket) r = redis.StrictRedis(connection_pool = pool) iid = r.incr('image') now = time.time() r.zadd('image:created_on', now, iid) k = Key(mybucket) k.key = iid k.set_contents_from

Dynamic Flask-Form construction intended for use under Jinja

亡梦爱人 提交于 2019-12-11 23:27:17
问题 My purpose is to construct a form with dynamicly provided labels and use it in Jinja Form. This made me reveal multiple fundemental questions. As in the exemple here from flask_wtf import FlaskForm from wtforms import SubmitField from wtforms.validators import DataRequired class LoginForm(FlaskForm): # submit = SubmitField('Go On') def __init__(self, BtnLble): self.submit = SubmitField(BtnLble,form=self, name="MySbmt", _meta=self.Meta) # self.submit.bind(form=self, name="MySbmt", _meta=self

assigning css class to form element passed from flask to jinja

隐身守侯 提交于 2019-12-11 15:46:16
问题 I am quite new to jinja / flask, I am creating dymnamic form in my flask app: class CreateForm(FlaskForm): searchCity = StringField('View forcast of city:', validators=[InputRequired("Please enter the city you want to check weather updates")]) count = IntegerField("Days") submit = SubmitField("Submit") form = CreateForm(request.form) form.count.default = count form.count.label = "Days" if count > 1 else "Day" form.count.data = count and in jinja template: <form> <dl> <dd>{{ form.searchCity

Using WTForms populate_obj to update many-to-many association table with extra column

倖福魔咒の 提交于 2019-12-11 14:05:17
问题 In my application, a ' set ' can have a number of ' products ' associated with it. Products listed against a set must have quantities defined. For this many-to-many relationship I have followed the SQLAlchemy documentation to use an association table with an additional column ( quantity ). With the code included below, I am able to successfully update existing (manually entered) data in my tables using a form generated with Flask-WTF, but I am not able to add a new 'association'. I receive

Can't post Flask form data for testing (FieldList) [DeprecationWarning]

半城伤御伤魂 提交于 2019-12-11 10:48:42
问题 I'm writing several different flask forms. So far, what I've done to test the routes that I use with those forms is. Creating the form object Populating the form Posting the form data For example, this works (short version of the class): class RequestForm(FlaskForm): project = SelectField(label='Project', id='project', coerce=str) name = StringField('Environment Name', id='env_name', validators=[DataRequired()]) requested_by = StringField('Requested By', validators=[DataRequired()]) tag =