Can't dynamicaly populate IntegerField/DecimalField on a web form

Hi!
I’m new to python, trying to figure out how to populate fields on a webform with python code.
I hope i’m submitting the question to the right forum…

I’m using a WTForms. On the form I have a few DecimalField and IntegerField fields.
An example (forms.py file):

forms.py

from flask import Flask
from flask_wtf import FlaskForm
from wtforms.fields import *

app = Flask(name)

class myForm(FlaskForm):
price = DecimalField(“Retail Price”, default=0)
qty = IntegerField(“Quantity”, default=0)
name = StringField(“Product Name”)
submit = SubmitField(‘Submit’,id=“submit”)

if name==“main”:
app.run(debug=True)

In an html page (home.html) they are represented like:

Home.html

{{ form.hidden_tag() }}
{{ form.name.label }} {{ form.name }}
{{ form.qty.label }} {{ form.qty }}
{{ form.price.label }} {{ form.price }}

{{ form.submit() }}

When a user clicks the Search button the page has to populate all fields with values from a database.

Here is my shortened version of the main python page (basic.py):

basic.py

from flask import Flask
from flask_wtf import FlaskForm
from wtforms.fields import *
from forms import *

app = Flask(name)
@app.route(’/’, methods=[‘GET’,‘POST’])

def index():
form=myForm()
if form.validate_on_submit():
if request.form[‘submit’] == ‘Search’:
# the Search button was clicked so the fields are populated with a database retrieved values
form.name.default = “Cabernet Sauvignon” # this field is populated just fine
form.price.default = 23.45 # this line doesn’t populate the value into the field though
form.qty.default = 5 # this line doesn’t populate the value into the field either
else: # user has field in the form so the input is going to be entered into the database.
# This part works just fine.
price = form.price.data
qty = form.qty.data
name = form.name.data
return render_template(‘home.html’, form=form)

if name==‘main’:
app.run(debug=True)

StringField fields populate fine with this code. I have problems with DecimalField and IntegerField fields. They don’t populate.
So when a user hits the Search button, price and qty fields though still have 0.00 and 0 inside the input boxes of the fields.

I also have tried to assign the values to my DecimalField and IntegerField in the def index() removing the “default” property like that:
form.price = 23.45
form.gty = 5

When so, what it does on the home.html page then is:
the input parts of the price and qty fields disappear and the values 23.45 and 5 are shown as the labels of those fields, so that the labels no longer say “Retail Price” and “Quantity”, but instead they say “23.45” and “5”. And there’s no input boxes next to the labels.

Can anyone please suggest how to assign values, so the labels stay “Retail Price” and “Quantity” and next to them there are input box fields with values 23.45 and 5? :slight_smile: Am I using wrong properties of those fields?
Thank you much in advance!
I’m sorry tabulations within code samples were not kept when i posted the question.