wtforms

flask wtf.quick_form running some javascript and setting a form variable

混江龙づ霸主 提交于 2019-12-11 12:56:36
问题 I am creating blog posts and have so far done it with a normal html form. One funky think I was doing was running javascript onclick and setting a hidden variable in the form with extra data from the page. This was passed to the server just fine and gotten with request.form. Now I want to use wtf.quick_form for the entering of blog posts. qtf.quick_form works great for simple things, but now I need to run some javascript on click and then set a form variable. At the server, I need to retrieve

Update model with WTForms form data

本秂侑毒 提交于 2019-12-11 08:27:17
问题 I have some Flask-SQLAlchemy models and Flask-WTF forms generated with wtforms_alchemy to represent them. I implemented a method on each model to update its attributes from a form's data. For each new model and field I have to update these methods, which is annoying. Is there a way to make this more automatic, or a a feature in the libraries I'm using that I'm missing? def edit_car(car_id): form = CarForm(request.form) if form.is_valid(): car = Car.query.get_or_404(car_id) car.from_form(form)

How do i make multiple checkbox with a unique id using WTForms so that i can store it in shelves?

。_饼干妹妹 提交于 2019-12-11 07:53:03
问题 How can I make multiple checkbox using WTForms and render it to my html page? This is what i've come up with using WTForms but i was told that by using Boolean(True,False) it will only applies to only one checkbox instead of multiple checkbox.And how can i append the selected check-boxes into a dictionary with a unique ID given to it? Im quite new to python,flask and WTForms. Thank you for taking your time to help me out. It is also fine to give me some suggestions/guides to help me work on

Generating a CSRF token manually with Flask WTF-Forms

荒凉一梦 提交于 2019-12-11 07:34:07
问题 I'd like to create and fill out a Flask WTF-Form using only python code. However, the form doesn't automatically generate a CSRF token when I create it with python code. Is there any way to do this manually? The form in question: from flask_wtf import Form from wtforms import StringField from wtforms.validators import DataRequired, URL class URLForm(Form): url = StringField('url', validators=[DataRequired(), URL(), Level3Url()]) the code I use to generate the form: from forms import URLForm

WTForms-Javascript: pass onclick to WTF field

爱⌒轻易说出口 提交于 2019-12-11 07:02:27
问题 Is there a way to pass "onclick" onto a WTForm field? I'd like to enable/disable a field depending on whether a WTF checkbox is selected. But the HTML from WTForms does not create or have an "onclick" parameter. I have a form: class test(Form): checkbox=BooleanField('Checkbox') required=TextField('Required if checked') and I have the JS: function disablefld(){ cb=document.getElementById('checkbox').checked; document.getElementById('required').disabled=!cb; } The HTML WTForms generated for the

WTForm: how do I tell Form to use a custom method for one particular attribute?

余生长醉 提交于 2019-12-11 05:29:57
问题 I have the following definitions: class ProduceType(ndb.Model): crop = ndb.StringProperty() variety = ndb.StringProperty() class OrderEntry(ndb.Model): producetype = ndb.KeyProperty(kind=ProduceType, required=True) quantity = ndb.IntegerProperty(required=True) I created the following WTForm: class OrderEntryForm(Form): quantity = IntegerField('Quantity', [validators.Required(), validators.NumberRange(min=1)]) # we will be dynamically adding choices producetype = SelectField('Produce',

How to populate a submit popup based on the value you filled to evaluate a condition | flask

女生的网名这么多〃 提交于 2019-12-11 04:46:46
问题 I have a jinja html template which has a form. The form is a wtforms , assume it like >>> from wtforms import Form, BooleanField, IntegerField, SelectField, StringField, validators >>> class COOLForm(Form): action = SelectField('Action', description='Action', choices=[('online', 'ONLINE'), ('offline', 'OFFLINE')]) ... The html template looks something like <div class = "major" <form id="blah"> <input type="hidden"> {{ forms.form_field(coolform.action) }} . . </div> Then in the same file i

Embed HTML tag in Flask WTForms field

夙愿已清 提交于 2019-12-11 04:42:38
问题 I'm using Flask with Jinja2/WTForms to build a login page and I want to customize a "Remember Me" checkbox. To do this, I would like to embed an empty <span> tag into the form's label field. Here is the Jinja2 code in the HTML file: {{ login_user_form.remember|safe }} {{ login_user_form.remember.label }} which generates the following HTML: <input id="remember" name="remember" type="checkbox" value="y"> <label for="remember">Remember Me</label> However, the following HTML is what I would

No module named flask.ext.wtf.SelectField

╄→гoц情女王★ 提交于 2019-12-11 03:54:06
问题 I found flask-jquery-ajax-example and I tried to run it with the latest library versions: $ pip install flask flask-wtf wtforms $ pip install -e ./ However, I got the ImportError: No module named flask.ext.wtf.SelectField while starting the scripts: $ python bin/runserver.py Traceback (most recent call last): File "bin/runserver.py", line 2, in <module> from fjae import run_dev_server File "/home/mic/tmp/flask-jquery-ajax-example/fjae/__init__.py", line 3, in <module> from fjae import views

Why doesn't my WTForms-JSON form update correctly?

爱⌒轻易说出口 提交于 2019-12-11 03:47:02
问题 I am developing a web page that reads JSON and presents it in a form using WTForms-JSON. When I submit the form, form.data isn't updated. Why isn't this working? views.py : from flask import render_template, flash, redirect, request from app import app from .forms import PolicyForm import json import urllib2 @app.route('/policy', methods=['GET', 'POST']) def policy(): url = 'http://dcdemoappsrv1:8081/direct/policy?policyNumber=000000005&everything=true&discounts=true&coverages=true&vehicles