Opened 5 years ago

Closed 5 years ago

#16851 closed Uncategorized (fixed)

Accessing a forms field value in a template

Reported by: from_a_far@… Owned by: Yaşar Arabacı
Component: Documentation Version: 1.3
Severity: Normal Keywords:
Cc: Yaşar Arabacı Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: yes UI/UX: no

Description

Please could someone put in the documentation that you can access a forms field value in a template by using the following

{{ form.apple.value }}

I only ask because I couldn't find anything on the web about and it's only by trying it that I found it worked

Attachments (2)

form_value.diff (654 bytes) - added by Yaşar Arabacı 5 years ago.
Added required documentation items
0001-Added-field.value-explanation.patch (827 bytes) - added by Yaşar Arabacı 5 years ago.
Removed extra remarks about null value

Download all attachments as: .zip

Change History (12)

comment:1 Changed 5 years ago by Carl Meyer

Triage Stage: UnreviewedAccepted

comment:2 Changed 5 years ago by linovia

Actually, {{ form.apple.value }} will not be correct if value is None.
{{ form.apple.value|default_if_none:"" }} is a better choice.

comment:3 Changed 5 years ago by Yaşar Arabacı

Cc: Yaşar Arabacı added
Owner: changed from nobody to Yaşar Arabacı
Status: newassigned

Changed 5 years ago by Yaşar Arabacı

Attachment: form_value.diff added

Added required documentation items

comment:4 Changed 5 years ago by Yaşar Arabacı

Has patch: set
Triage Stage: AcceptedReady for checkin

comment:5 Changed 5 years ago by Yaşar Arabacı

Cc: Yaşar Arabacı removed

comment:6 Changed 5 years ago by Yaşar Arabacı

Cc: Yaşar Arabacı added

comment:7 Changed 5 years ago by Aymeric Augustin

Triage Stage: Ready for checkinAccepted

See #16758 - same comment. Also, note that you don't need to add yourself in Cc explicitly. If you've contributed to a ticket (written a comment, uploaded a patch...) Trac will always notify you of updates.

comment:8 Changed 5 years ago by Bas Peschier

Patch needs improvement: set

Nice and simple addition to the docs, but I do not really agree with the remark about it not being "correct" and one "should" use the default filter: an empty string is not technically None either. Encountering None in templates is something more general and does not need to get mentioned here.

Changed 5 years ago by Yaşar Arabacı

Removed extra remarks about null value

comment:9 Changed 5 years ago by Christopher Medrela

Triage Stage: AcceptedReady for checkin

comment:10 Changed 5 years ago by Tim Graham

Resolution: fixed
Status: assignedclosed

In [17138]:

Fixed #16851 - Added how-to access form field value in template; thanks yasar11732 for the patch.

Note: See TracTickets for help on using tickets.
Back to Top