From 7ac86d17c8d1d39269a4064e9fc2e96c2fd125da Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 14 Sep 2008 23:55:09 +0000 Subject: [PATCH] Added documentation for looping over a form's fields in a template git-svn-id: http://code.djangoproject.com/svn/django/trunk@9030 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- docs/topics/forms/index.txt | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/docs/topics/forms/index.txt b/docs/topics/forms/index.txt index 5cc76bdee8..a8ae0ef922 100644 --- a/docs/topics/forms/index.txt +++ b/docs/topics/forms/index.txt @@ -249,6 +249,44 @@ over them:: {% endfor %} {% endif %} + +Looping over the form's fields +------------------------------ + +If you are using the similar HTML for each of your form fields, you can +reduce duplicate code by looping through each field in turn using +``{% for field in form %}``:: + +
+ {% for field in form %} +
+ {{ field.errors }} + {{ field.label_tag }}: {{ field }} +
+ {% endfor %} +

+
+ +As in the above example, {{ field.errors }} will output a +``