From 232b60a21b951bd16b8c95b34fcbcbf3ecd89fca Mon Sep 17 00:00:00 2001 From: David Smith Date: Sun, 12 Feb 2023 13:20:05 +0000 Subject: Refs #32339 -- Updated docs to reflect default
style form rendering in Django 5.0. Follow up to 98756c685ee173bbd43f21ed0553f808be835ce5. --- docs/ref/forms/api.txt | 79 +++++++++++++++++++------------------------------- 1 file changed, 30 insertions(+), 49 deletions(-) (limited to 'docs/ref/forms/api.txt') diff --git a/docs/ref/forms/api.txt b/docs/ref/forms/api.txt index 8a18e1b5da..3a9ea81723 100644 --- a/docs/ref/forms/api.txt +++ b/docs/ref/forms/api.txt @@ -276,9 +276,9 @@ precedence: ... comment = forms.CharField() >>> f = CommentForm(initial={'name': 'instance'}, auto_id=False) >>> print(f) - Name: - Url: - Comment: +
Name:
+
Url:
+
Comment:
.. method:: Form.get_initial_for_field(field, field_name) @@ -500,10 +500,10 @@ The second task of a ``Form`` object is to render itself as HTML. To do so, >>> f = ContactForm() >>> print(f) - - - - +
+
+
+
If the form is bound to data, the HTML output will include that data appropriately. For example, if a field is represented by an @@ -519,16 +519,14 @@ include ``checked`` if appropriate: ... 'cc_myself': True} >>> f = ContactForm(data) >>> print(f) - - - - +
+
+
+
-This default output is a two-column HTML table, with a ```` for each field. -Notice the following: +This default output wraps each field with a ``
``. Notice the following: -* For flexibility, the output does *not* include the ```` and - ``
`` tags, nor does it include the ``
`` and ``
`` +* For flexibility, the output does *not* include the ``
`` and ``
`` tags or an ```` tag. It's your job to do that. * Each field type has a default HTML representation. ``CharField`` is @@ -556,7 +554,7 @@ Notice the following: it uses boolean attributes such as ``checked`` rather than the XHTML style of ``checked='checked'``. -Although ```` output is the default output style when you ``print`` a +Although ``
`` output is the default output style when you ``print`` a form, other output styles are available. Each style is available as a method on a form object, and each rendering method returns a string. @@ -584,7 +582,7 @@ class. .. method:: Form.render(template_name=None, context=None, renderer=None) -The render method is called by ``__str__`` as well as the +The render method is called by ``__str__`` as well as the :meth:`.Form.as_div`, :meth:`.Form.as_table`, :meth:`.Form.as_p`, and :meth:`.Form.as_ul` methods. All arguments are optional and default to: @@ -779,11 +777,11 @@ classes, as needed. The HTML will look something like: .. code-block:: pycon >>> f = ContactForm(data) - >>> print(f.as_table()) -
- - - - >>> print(f.as_ul()) -
    • This field is required.
    Subject:
  • -
  • Message:
  • -
    • Enter a valid email address.
    Sender:
  • -
  • Cc myself:
  • - >>> print(f.as_p()) -

    • This field is required.

    -

    Subject:

    -

    Message:

    -

    • Enter a valid email address.

    -

    Sender:

    -

    Cc myself:

    .. _ref-forms-error-list-format: @@ -1515,7 +1496,7 @@ fields are ordered first: >>> class ContactFormWithPriority(ContactForm): ... priority = forms.CharField() >>> f = ContactFormWithPriority(auto_id=False) - >>> print(f.as_div()) + >>> print(f)
    Subject:
    Message:
    Sender:
    @@ -1538,7 +1519,7 @@ classes: >>> class BeatleForm(InstrumentForm, PersonForm): ... haircut_type = forms.CharField() >>> b = BeatleForm(auto_id=False) - >>> print(b.as_div()) + >>> print(b)
    First name:
    Last name:
    Instrument:
    @@ -1575,10 +1556,10 @@ You can put several Django forms inside one ```` tag. To give each >>> mother = PersonForm(prefix="mother") >>> father = PersonForm(prefix="father") - >>> print(mother.as_div()) + >>> print(mother)
    - >>> print(father.as_div()) + >>> print(father)
    -- cgit v1.3
    ... -
    ... -
    ... -
    Subject:
    • This field is required.
    Message:
    Sender:
    • Enter a valid email address.
    Cc myself: