Re: [flask] Flask-WTF and
- From:
- lynadge
- Date:
- 2012-01-29 @ 22:07
Perfect, it works. :)
SampleForm(Form):
text = TextField()
form = SampleForm(text='Default Value')
Thank. :)
Am 29.01.2012 15:51, schrieb Amirouche Boubekki:
> 2012/1/29 lynadge <lynadge@barfooz.de [1]>
>
>> Hi,
>
> Héllo lynadge,
>
>> i use flask-wtf and wtforms for a form to create and update
>> entries.
>>
>> My problem is, when i try to edit and prepopulate the form for
>> updating
>> an entry i can't find a way.
>>
>> The form is also created. So my question, how can i set the
>> defaults in
>> my form after the form is created?
>
> Did you look at wtforms' Forms construction method documentation
> http://wtforms.simplecodes.com/docs/0.6.1/forms.html#the-form-class
> [2] ?
>
> You can use an obj parameter or **kwargs arguments.
>
> HTH,
>
> Amirouche
>
>
>
> Links:
> ------
> [1] mailto:lynadge@barfooz.de
> [2]
> http://wtforms.simplecodes.com/docs/0.6.1/forms.html#the-form-class
Re: [flask] Flask-WTF and
- From:
- Simon Zimmermann
- Date:
- 2012-01-30 @ 11:12
On 29 January 2012 23:07, lynadge <lynadge@barfooz.de> wrote:
> Perfect, it works. :)
>
> SampleForm(Form):
> text = TextField()
>
> form = SampleForm(text='Default Value')
It should be noted that `formdata` and `obj` take precedence over
`**kwargs`. The order of precedence is `formdata` -> `obj` ->
`**kwargs`. To update an obj the `populate_obj` method is also quiet
handy. It loops through each of the fields in the form and calls
setattr(obj, field, value).