#31158 closed Uncategorized (wontfix)
_password_validators_help_text_html() returns HTML block level element.
Reported by: | Carsten Fuchs | Owned by: | nobody |
---|---|---|---|
Component: | contrib.auth | Version: | 3.0 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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 withf.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:
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))
Change History (2)
comment:1 by , 5 years ago
Component: | Forms → contrib.auth |
---|---|
Resolution: | → wontfix |
Status: | new → closed |
Summary: | _password_validators_help_text_html() returns HTML block level element → _password_validators_help_text_html() returns HTML block level element. |
comment:2 by , 4 years ago
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.
password_validators_help_text_html()
was introduced in 1daae25bdcd735151de394a5578c22257e3e5dc7, this behavior is expected and documented. If you don't like it you can always subclass forms fromdjango.contrib.auth.forms
and use you own method orpassword_validators_help_texts()
.