python - Any easy way to do 'mad lib' style form fields in Django? -



python - Any easy way to do 'mad lib' style form fields in Django? -

i curious making "mad lib" style form (cf. http://www.lukew.com/ff/entry.asp?1007) django form. iterating on form fields , laying out text hand, e.g. <li>there should {{ form.num_widgets }} widgets</li>, dislike how label on form field unused, how it's partially spread form definition file , template file, , how it's hard i18n that.

is there neater/all-in-one-place way mad lib forms in django? set label of widget "there should %(something)s widgets", , it'll replace %(something)s rendered form of field, can phone call {{ form.as_p }} , it'll work automatically?

this case custom template tag, documented here: https://docs.djangoproject.com/en/dev/howto/custom-template-tags/

you create tag along lines of:

@register.simple_tag def madlibfield(formfield): homecoming formfield.label % formfield

you utilize in template

{% madlibfield form.num_widgets %}

if want fancier output (like replicating as_p functionality), it's trivial in tag.

python django django-forms

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -