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.
* 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>
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>