Hi,
if the form is bound (i.e. form.is_bound is true) then you can access
its data attribute, which contains the data entered into the form.
If the form is valid (i.e. form.is_valid() is true), then you can
access the cleaned_data attributes as well.
So for example if you have form like this:
f = MyForm({ "last_name": "some_value"})
you can access the value in template in this way
{{ f.data.last_name }}
or alternatively, if your form is valid you can use:
{{ f.cleaned_data.last_name }}
Just bear in mind, that the two values can be different since
cleaned_data the result of some processing in the validation methods.
hope it helps,
-Ondrej Bohm
On Jan 17, 7:35 pm, adrian_m <[email protected]> wrote:
> Hello people,
>
> How can I access the value of a form field in the template ? I'm
> having
> two different use cases :
> - display a field value as simple text (the field is not meant to be
> edited
> by the user, therefore i don't want to use a input field)
> - use the field value for generating a link
> ( something like this: <a href="{% url cmds.views.details
> form.cmd_id.value %}">Details</a> )
>
> It would have been nice to have an attribute
> {{form.field_name.value}}
> which would return the value instead of a widget.Unfortunately there
> seems
> to be no such attribute available.
>
> I have looked at the Field attributes and also at the list of
> available widgets,
> but none seems to do what I need : simply display the value as raw
> text
> instead of generating input field / textarea / etc. I guess that my
> use cases
> are frequent enough, so there must be some simple way to do it ...
>
> (if it makes any difference: i am actually trying to use a forms set,
> and
> in each of the forms i want to create "details" and "delete" links
> using
> the id of the current record).
>
> Thanks in advance for any tips,
> Adrian
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.