Opened 14 years ago
Closed 14 years ago
#16851 closed Uncategorized (fixed)
Accessing a forms field value in a template
| Reported by: | 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)
Change History (12)
comment:1 by , 14 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:2 by , 14 years ago
comment:3 by , 14 years ago
| Cc: | added |
|---|---|
| Owner: | changed from to |
| Status: | new → assigned |
comment:4 by , 14 years ago
| Has patch: | set |
|---|---|
| Triage Stage: | Accepted → Ready for checkin |
comment:5 by , 14 years ago
| Cc: | removed |
|---|
comment:6 by , 14 years ago
| Cc: | added |
|---|
comment:7 by , 14 years ago
| Triage Stage: | Ready for checkin → Accepted |
|---|
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 by , 14 years ago
| 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.
by , 14 years ago
| Attachment: | 0001-Added-field.value-explanation.patch added |
|---|
Removed extra remarks about null value
comment:9 by , 14 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
Actually, {{ form.apple.value }} will not be correct if value is None.
{{ form.apple.value|default_if_none:"" }} is a better choice.