Opened 3 weeks ago

Closed 3 weeks ago

Last modified 3 weeks ago

#37186 closed Cleanup/optimization (invalid)

Document form Field's template_name argument

Reported by: Tim Schilling Owned by:
Component: Documentation Version: dev
Severity: Normal Keywords: form rendering
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

The change to support form field rendering in Ticket #34077 stopped short of documenting that a field can have a customized template specified on the field itself. This template would be passed to the BoundField which we have public documentation for.

This change would mean documenting template_name in the Field.__init__ method here.

I suppose one reason to not do this is if this particular API isn't something we want to commit to. I think since it hasn't changed in a few years, it appears stable.

The usage we'd want to make developers aware of is that they can do today:

class ProfileForm(forms.Form):
    image = forms.ImageField(
        template_name="my_forms/fields/image_with_preview.html"
    )

Change History (2)

comment:1 by Mike Edmunds, 3 weeks ago

Resolution: invalid
Status: newclosed

Maybe I'm missing something, but django.forms.fields.Field.template_name is documented in the form fields reference, as one of the "core field arguments."

The block comment in the fields.py implementation isn't used as documentation source. (It's a typo in the code that template_name is missing from that comment. But template_name is already documented in the official documentation, which is what matters for whether it's considered supported.)

comment:2 by Tim Schilling, 3 weeks ago

You're right! I have no idea where I was looking for it...

Note: See TracTickets for help on using tickets.
Back to Top