Opened 11 years ago

Closed 8 years ago

#7511 closed New feature (wontfix)

Automatically generate templates for newforms

Reported by: Daniel Pope <dan@…> Owned by: nobody
Component: Forms Version: master
Severity: Normal Keywords: wishlist
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


One of the problems with using newforms at the moment is that while the form.as_*() methods offer a shortcut for generating a functional form, there is no simple migration path to go from using {{form.as_p}} in templates, to the template syntax for the same, as is necessary for further customisation.

I suggest there should be a management command to generate template code for a given form:

With this in myapp/myproject/

class MyForm(forms.Form):
    name = forms.CharField(help_text=u"Lorem ipsum dolor sit amet")
    type = forms.ChoiceField(choices=[('a', 'Type A'), ('b', 'Type B')], widget=forms.RadioSelect)

you might do:

$ python formtemplate myapp.myproject.forms.MyForm
<p>{{}} {{}}</p>
<p class="help_text">{{}}</p>


This could be pasted or piped into a template.

There is some complication for the same reason as #6388, as illustrated above, and the choice of what to output statically at compile time and what to determine at runtime is somewhat arbitrary. But the aim of this tool would be to assist in generating something editable, so if the form has been made dynamic in some way (eg. self.fields modified in the form constructor) this would still provide a useful foundation to customise manually.

Change History (4)

comment:1 Changed 11 years ago by adamfast

milestone: post-1.0
Triage Stage: UnreviewedDesign decision needed

comment:2 Changed 10 years ago by (none)

milestone: post-1.0

Milestone post-1.0 deleted

comment:3 Changed 8 years ago by Luke Plant

Severity: Normal
Type: New feature

comment:4 Changed 8 years ago by Carl Meyer

Easy pickings: unset
Resolution: wontfix
Status: newclosed
UI/UX: unset

This is a great example of the kind of utility that would be a really nice contribution as an external app for those who want it, but has no need to be in core.

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