Django — Access Form Value in View / Python

Somehow I needed to dig through the source to figure this one out.. it’s not obvious.

From a forms constructor, you must access the widget and its value_from_datadict method, which must be passed a decent length of arguments (, self.files, self.prefix(fieldname)).

Turns out there’s an internal function called `bound_form._raw_value(‘fieldname’)` which will get you the data without typing so much.

Why it’s so hidden? I’m not sure.

Note that you would use this when you don’t have access to the actual, post cleaned form which would have done the type conversion and validation for you.

This raw value is going to be a string.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s