Hi all,
I'm currently working on my first Django project and have run into a
difficulty while trying to write a generic "display a form" template
that I can {% include %} when I need to (as suggested in the
documentation <
http://docs.djangoproject.com/en/dev/topics/forms/>).
My goal is a simple template which renders each [visible] form field
in a div with an id ("{{ field.auto_id }}_wrapper") and a few classes.
In particular, I need to add a class so that different types of form
field can be styled differently w.r.t. their labels and errors.
I generally accomplish this with markup like:
<div id="id_tos_wrapper" class="form-field form-checkbox">
<label for="id_tos">I agree to the terms of service.</label>
<input name="tos" type="checkbox" id="id_tos" />
</div>
I've been trying to find out how to accomplish this in Django
templates, but the closest I've been able to find are two threads on
this list <
http://groups.google.com/group/django-users/browse_thread/
thread/d5368f47ff247674> and <
http://groups.google.com/group/django-
users/browse_thread/thread/a2aa180890fdd4de> which both seem to
indicate that it is impossible at the template level to get any
information about a form field beyond its auto_id, errors, and the
HTML for the label, input, etc.
This has been trivial in every other framework I've used and I'm sure
it is in Django as well, but I'm completely stumped. Is there any way
to do this which doesn't require that I write custom code for every
form and/or checkbox in my project?
Cheers,
Thomas Sutton