wtforms

Testing a POST that uses Flask-WTF validate_on_submit

ⅰ亾dé卋堺 提交于 2019-12-23 11:49:08
问题 I am stumped on testing a POST to add a category to the database where I've used Flask_WTF for validation and CSRF protection. For the CRUD operations pm my website. I've used Flask, Flask_WTF and Flask-SQLAlchemy. It is my first independent project, and I find myself a little at a lost on how to test the Flask-WTForm validate_on_submit function. Here's are the models: class Users(db.Model): id = db.Column(db.Integer, primary_key=True, unique=True) name = db.Column(db.String(80), nullable

Testing a POST that uses Flask-WTF validate_on_submit

﹥>﹥吖頭↗ 提交于 2019-12-23 11:49:07
问题 I am stumped on testing a POST to add a category to the database where I've used Flask_WTF for validation and CSRF protection. For the CRUD operations pm my website. I've used Flask, Flask_WTF and Flask-SQLAlchemy. It is my first independent project, and I find myself a little at a lost on how to test the Flask-WTForm validate_on_submit function. Here's are the models: class Users(db.Model): id = db.Column(db.Integer, primary_key=True, unique=True) name = db.Column(db.String(80), nullable

WTForms “too many values to unpack” with SelectField

倾然丶 夕夏残阳落幕 提交于 2019-12-23 07:40:09
问题 I'm using WTForms and I'm trying to display a SelectField , but I get the following error: >>> form.status() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python26\Lib\site-packages\wtforms\fields.py", line 136, in __call__ return self.widget(self, **kwargs) File "C:\Python26\Lib\site-packages\wtforms\widgets.py", line 237, in __call__ for val, label, selected in field.iter_choices(): File "C:\Python26\Lib\site-packages\wtforms\fields.py", line 390, in iter

WTForms “too many values to unpack” with SelectField

不想你离开。 提交于 2019-12-23 07:40:07
问题 I'm using WTForms and I'm trying to display a SelectField , but I get the following error: >>> form.status() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python26\Lib\site-packages\wtforms\fields.py", line 136, in __call__ return self.widget(self, **kwargs) File "C:\Python26\Lib\site-packages\wtforms\widgets.py", line 237, in __call__ for val, label, selected in field.iter_choices(): File "C:\Python26\Lib\site-packages\wtforms\fields.py", line 390, in iter

Setting a default on a select removes the settings passed in to populate the form

爱⌒轻易说出口 提交于 2019-12-22 18:16:18
问题 This code works fine separately. What I mean is when I set the default tag and call process() all the other data that should populate the form have been removed. In this case the default is ok, but the other fields are empty. form = ReviewForm(**populate_form) form.tags.default = '1' form.process() So, it seems like process cleans the **populate_form values out. I need to populate all fields and then set the default for the select. 回答1: From the WTForms Documentation: Since BaseForm does not

WTForms-JSON not working with FormFields

穿精又带淫゛_ 提交于 2019-12-22 08:34:49
问题 Nested forms (FormFields) doesn't get populated with data when I use WTForms-JSON. I can't spot my mistake, see example below. from flask import Flask, request, jsonify from flask_wtf import Form from wtforms import TextField, FormField, IntegerField from wtforms.validators import InputRequired import wtforms_json app = Flask(__name__) app.config["WTF_CSRF_ENABLED"] = False wtforms_json.init() class Address(Form): street = TextField('street', validators=[InputRequired()]) number =

can't append_entry FieldList in Flask-wtf more than one

你。 提交于 2019-12-21 15:19:13
问题 I have form with flask-wtf for upload some image, also file field can be multiple my form: class ComposeForm(Form): attachment = FieldList(FileField(_('file')), _('attachment')) add_upload = SubmitField(_('Add upload')) my view: if form.validate_on_submit(): if form.add_upload.data: form.attachment.append_entry() return render_template('mailbox/compose.html', form=form) else: form.attachment.append_entry() my template : <form method="POST" enctype="multipart/form-data" action="."> {% for

How to render my select field with WTForms?

北慕城南 提交于 2019-12-21 05:28:07
问题 I have a select field that has certain elements faded and disabled that I would like to render with WTForms: <select name="cg" id="cat" class="search_category"> <option value='' >{% trans %}All{% endtrans %}</option> <option value='' style='background-color:#dcdcc3' id='cat1' disabled="disabled">-- {% trans %}VEHICLES{% endtrans %} --</option> <option value='2' {% if "2" == cg %} selected="selected" {% endif %} id='cat2' >{% trans %}Cars{% endtrans %}</option> <option value='3' {% if "3" ==

WTforms form not submitting but outputs no validation errors

柔情痞子 提交于 2019-12-21 02:56:06
问题 I'm trying to get file uploads with flask-uploads working and running in to some snags. I'll show you my flask view function, the html and hopefully someone can point out what I'm missing. Basically what happens is that I submit the form and it fails the if request.method == 'POST' and form.validate(): check in the view function. It jumps down to display the template. wtforms isn't kicking me any errors on the form so I'm wondering why its failing that if statement. What am I over looking?

SelectField in wtforms and added <option> via javascript

只谈情不闲聊 提交于 2019-12-21 00:51:11
问题 I'm currently work on some project in pyramid and have problem with wtforms SelectField. I have a 3 SelectField fields: car_make (e.g., "audi") car_model (e.g., "audi 80") car_version (e.g., "AUDI 80 B4"). The car_make choices I can load in the view. The choices for rest of SelectFields (car_model, car_version) I will load on the client side via AJAX/javascript (I can choose car_model when car_make is selected and so on). The problem is that when I submit the form, car_model and car_version