wtforms

How to populate my WTForm variables?

房东的猫 提交于 2020-01-12 12:24:52
问题 I'm enabling a function that can edit an entity. I want to populate the form with the variables from the datastore. How can I do it? My code doesn't populate the form: if self.request.get('id'): id = int(self.request.get('id')) ad = Ad.get(db.Key.from_path('Ad', id)) im = ad.matched_images editAdForm = AdForm(ad) if str(users.get_current_user()) == str(ad.user) or users.is_current_user_admin(): self.render_jinja('edit', form_url=blobstore.create_upload_url('/addimage'), admin=users.is_current

Form is never valid with WTForms

倖福魔咒の 提交于 2020-01-09 02:40:07
问题 I have a Flask-WTF form for sign in. Apparently the form is never valid, no matter what I enter "success" is never printed. Why isn't my form validating? class loginForm(Form): email = EmailField('email', validators=[InputRequired("Please enter your email address."), Email("Please enter a valid email address.")]) password = PasswordField('password', validators=[InputRequired("Please enter your password.")]) @app.route('/sign-in', methods=['POST', 'GET']) def signIn(): form = loginForm(request

How to repopulate WTForms

倾然丶 夕夏残阳落幕 提交于 2020-01-07 04:00:33
问题 so i have made a form in WTForms with an edit button which allows the user to edit the previous data in the form. The problem i have is fetching the new data from the form.when i do request.form i get the following: ImmutableMultiDict([('csrf_token', u'20130702225444##3f1c28cecaf55dc0e441d9820dfb52bb6df3d200'), ('csrf_token', u'20130702225444##3f1c28cecaf55dc0e441d9820dfb52bb6df3d200'), ('csrf_token', u'20130702225444##3f1c28cecaf55dc0e441d9820dfb52bb6df3d200'), ('csrf_token', u

WTForms fieldlist 'StringField' object is not iterable error

巧了我就是萌 提交于 2020-01-06 06:57:16
问题 I'm getting this error only when the field is defined in a form that contains other fields- but when its defined in a it's own form, this error is not generated and it works. Firstly I will show what works successfully: class TrackForm(Form): name = StringField('Name') start = StringField('Start') end = StringField('End') class Merge(Form): item_description = FieldList(FormField(TrackForm), min_entries=1, max_entries=32) view.py @app.route('/test', methods=['GET', 'POST']) def test(): form

Forwarding multipart/form-data to different service (python, bottle, requests)

你离开我真会死。 提交于 2020-01-05 21:20:08
问题 I have middle-layer api which receives request (form submit request with possibly with attachment) from client and verify couple of things (form validation using WTForms) and then forward form post request to another service which actually performs actions on that. Problem I am facing is not able to forward request data and files attached as it is, below is code example. @post('/') def index(): post_data = request.POST.dict requests.post("http://127.0.0.1:8090/", data=post_data, files=request

Flask/WTForms - post request doesnt send input

不羁岁月 提交于 2020-01-05 09:30:15
问题 does somebody know why the body of my post request is None? I am using Flask with WTForms. My forms.py class SignupForm(Form): username = StringField('Username') password = PasswordField('Password') email = StringField('Email') submit = SubmitField('Create account') My route.py @app.route('/signup', methods=['GET', 'POST']) def signup(): form = SignupForm() if request.method == 'POST': app.logger.info(form.data) return redirect(url_for('signup')) elif request.method == 'GET': return render

Sorting WTForms form.errors dict

孤人 提交于 2020-01-03 17:10:45
问题 The forms.errors dict seems to be sorted on field name, and not on the order they are declared in the form itself. E.g. class ProductForm(Form): code = TextField('Code', validators=[Required()]) description = TextField('Description', validators=[Required(), Length(max=100)]) amount = DecimalField('Amount', validators=[Required(), NumberRange(min=0.00, max=1000000.00)]) vat_percentage = DecimalField('VAT %', validators=[Required(), NumberRange(min=0.00, max=100.00)]) inactive_date = DateField(

Flask app submit target=“_blank” form only after wtforms validation

懵懂的女人 提交于 2020-01-01 17:04:52
问题 In my Flask app I have a form generated with wtforms and jinja templates. If validation passes I want to redirect in a new tab, else I want to stay on the same page and display the errors. However if I set target="_blank" in my form, it opens a new tab without validation passing and shows the errors there. Removing target="_blank" will not open a new tab. Is there a way of achieving this without rewriting the whole validation in js? Thanks! Code: from wtforms import Form, TextAreaField,

Dynamic forms from variable length elements: wtforms

吃可爱长大的小学妹 提交于 2020-01-01 06:44:30
问题 I'm using wtforms, and I need to create a something that will generate a form definition based off information in a database; dynamic form creation. I'm getting a sense of what needs to be done and I've just started. I can create forms and use them with wtforms/flask but defining forms from data that will vary slightly from form to form is currently beyond my current skill level. Has anyone done this and have some input to offer? Somewhat a vague question, no actual code yet. I haven't found

Add fields dynamically to WTForms form

本小妞迷上赌 提交于 2019-12-29 07:46:10
问题 I want to define a form class with fields based on a dict of name: label . I tried the following, which nearly worked. However, rendering the fields in a template gave AttributeError: 'UnboundField' object has no attribute '__call__' . How can I dynamically add fields to a form? def build_form(name, record): class ContactForm(FlaskForm): name = StringField(name) fieldlist = {} for key, value in record.items(): fieldlist[key] = StringField(key) @app.route('/', methods=['GET', 'POST']) def