I would like to insert a header in a Django form. I have the following fields:
Name
Price
Optional - Size
Optional - Color
But instead of having the “Optional – ” in every optional item, I would like a header, so the form looks like this:
Name
Example
Optional fields:
Size
Color
(This is pseudocode but should be easy to illustrate my point)
I know i can render each individual form field in the HTML, but I would like to still use the {{ form.as_p }} (so I don’t have to change the markup for every new field I want to add). Is there any way to define a Django property for the form so I can preserve the form.as_p and still have this additional header (and more headers for more sections of fields)?
Thank you
Well, for lack of a better option, I solved this problem by rendering the form’s individual fields instead of the whole form.
Then I only have to do: