[Django] #31158: _password_validators_help_text_html() returns HTML block level element

15 views
Skip to first unread message

Django

unread,
Jan 10, 2020, 2:25:10 PM1/10/20
to django-...@googlegroups.com
#31158: _password_validators_help_text_html() returns HTML block level element
-----------------------------------------+------------------------
Reporter: Carsten Fuchs | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: 3.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
In `django.contrib.auth.password_validation`, function
`_password_validators_help_text_html()` returns a `<ul>` list, which is an
HTML block level element. (If I understood it correctly, this was
introduced in #26097.) This list is used as the `help_text` of a related
form field.

Imho, from the view of a template author for rendering the form, getting a
`<ul>` here is somewhat unexpected:

- Help texts are usually brief, one line statements that are written
inline in Field constructors calls; the Django documentation has numerous
examples.
- The documentation of `help_text` seems to expect such simple texts as
well: https://docs.djangoproject.com/en/3.0/ref/forms/fields/#help-text
shows the form rendered with `f.as_p()` at the bottom of the example.
- In many form (template) examples that I can find, including
Bootstrap's, `{{ field.help_text }}` is usually wrapped in `<p>` or
`<small>` elements.

As having block level elements in `<p>` or `<small>` is invalid HTML, I
suggest to join the strings of the password validators with a simple
`<br>` instead. For example:
{{{
#!python
def _password_validators_help_text_html(password_validators=None):
"""
Return an HTML string with all help texts of all configured
validators,
separated by <br> tags.
"""
help_texts = password_validators_help_texts(password_validators)
return mark_safe("<br>".join(escape(h) for h in help_texts))
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31158>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 10, 2020, 3:51:28 PM1/10/20
to django-...@googlegroups.com
#31158: _password_validators_help_text_html() returns HTML block level element.
-------------------------------+--------------------------------------

Reporter: Carsten Fuchs | Owner: nobody
Type: Uncategorized | Status: closed
Component: contrib.auth | Version: 3.0
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by felixxm):

* status: new => closed
* resolution: => wontfix
* component: Forms => contrib.auth


Comment:

`password_validators_help_text_html()` was introduced in
1daae25bdcd735151de394a5578c22257e3e5dc7, this behavior is expected and
[https://docs.djangoproject.com/en/3.0/topics/auth/passwords/#django.contrib.auth.password_validation.password_validators_help_text_html
documented]. If you don't like it you can always subclass forms from
`django.contrib.auth.forms` and use you own method or
`password_validators_help_texts()`.

--
Ticket URL: <https://code.djangoproject.com/ticket/31158#comment:1>

Django

unread,
Mar 15, 2021, 9:28:23 AM3/15/21
to django-...@googlegroups.com
#31158: _password_validators_help_text_html() returns HTML block level element.
-------------------------------+--------------------------------------

Reporter: Carsten Fuchs | Owner: nobody
Type: Uncategorized | Status: closed
Component: contrib.auth | Version: 3.0
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Meiyer):

I just came across this myself. While I accept Mariusz’s explanation (even
though I do not agree, as the `ul` being output by the function is
unexpected and breaks the typical help text output in `p` or `small`), I
do think that the documentation should be updated to clarify this point
and to show how to perform the customisation. In my opinion, this ticket
should be reopened as requesting change of documentation.

--
Ticket URL: <https://code.djangoproject.com/ticket/31158#comment:2>

Reply all
Reply to author
Forward
0 new messages