How set initial form field value in the view function?

1,090 views
Skip to first unread message

Chris Seberino

unread,
Jul 4, 2010, 11:26:13 AM7/4/10
to Django users
How set initial form field value in the view function?

The initial keyword is great when defining a subclass of Form if you
the initial values is ALWAYS the same.

What if it varies?...I'm guessing I must set it in the view.

How set this initial value in the view?

Chris

Jim

unread,
Jul 4, 2010, 1:27:25 PM7/4/10
to Django users
> The initial keyword is great when defining a subclass of Form if you
> the initial values is ALWAYS the same.
>
> What if it varies?...I'm guessing I must set it in the view.

From:
http://docs.djangoproject.com/en/1.2/ref/forms/api/#dynamic-initial-values
we have:
Dynamic initial values¶
Form.initial
Use initial to declare the initial value of form fields at runtime.
For example, you might want to fill in a username field with the
username of the current session.

Possibly you could restate your requirement? At least I'm not seeing
why
fm(initial={'x':variable_name})
won't help you.

Or possibly you want to override the __init__ method of the form?

Jim
Reply all
Reply to author
Forward
0 new messages