I am curious about making a “mad lib” style form (cf. http://www.lukew.com/ff/entry.asp?1007) for my django form. I could do it by iterating over all the form fields and laying out the text by hand, e.g. <li>There should be {{ form.num_widgets }} widgets</li>, however I dislike how the label on the form field is unused, how it’s partially spread from the form definition file and the template file, and how it’s hard to i18n that.
Is there any neater/all-in-one-place way to do mad lib forms in django? Something where I set the label of the widget to "There should be %(something)s widgets", and it’ll replace the %(something)s with the rendered form of the field, so that I can call {{ form.as_p }} and it’ll work automatically?
This is a good case for a custom template tag, as documented here: https://docs.djangoproject.com/en/dev/howto/custom-template-tags/
You could easily create a tag that does something along the lines of:
You could then use that in your template as
If you want to get fancier with the output (like replicating the
as_pfunctionality), it’s trivial to do so in the tag.