Q:

Prepopulate Flask-WTForm IntegerField

Simple form:
class AdjustPWMForm(Form):
    dutyCycle = IntegerField('dutycycle')
    #dutyCycle = IntegerField('dutycycle', default=44)

View function:
 def adjust():
    user = g.user
    form = AdjustPWMForm()
    form.dutyCycle.data = 55
    if form.validate_on_submit():
        dutyCycle = form.dutyCycle.data
        print('result %s', dutyCycle)
        return redirect(url_for('statusPage'))

    return render_template('adjust.html', title='Adjust PWM', user=user, form=form)

When the form is submitted, the result is always 55, regardless of what has been entered.   If I comment out the 55 line, and uncomment the line with the default=44, the form works properly, but I really need to be able to set the prepopulate value (it will be retrieved from the database). 
It seems like I'm missing something really obvious, but I've hunted around and can't figure it out. 
I found the section in change_username useful in wtforms which leads me to:
def adjust():
    user = g.user
    form = AdjustPWMForm(dutyCycle=55)
    if form.validate_on_submit():
        dutyCycle = form.dutyCycle.data
        return redirect(url_for('statusPage'))

    return render_template('adjust.html', title='Adjust PWM', user=user, form=form)

Is that the best way to accomplish this? 

A:

You could set the default value on a GET request
def adjust():
    user = g.user
    form = AdjustPWMForm()
    if request.method == 'GET':
        form.dutyCycle.data = 55
    if form.validate_on_submit():
        dutyCycle = form.dutyCycle.data
        print('result %s', dutyCycle)
        return redirect(url_for('statusPage'))
    return render_template('adjust.html', title='Adjust PWM', user=user, form=form)

or set a default value in the class
class AdjustPWMForm(Form):
    dutyCycle = IntegerField('dutycycle', default=55)

I would set the default in the class definition if the default works across all instances of this form.  If I need to set a default value for a field based on some other lookup, I would set it using the form = AdjustPWMForm(dutyCycle=55) way. 