Following this as a sample (from the docs you linked to):
widget=forms.TextInput(attrs={'class':'special'}))
You'd do this:
widget=forms.TextInput(attrs={'div_css':'test'}))
Or, to not clobber other things set in the form, you could do it in the
__init__:
#working example I just did in one of my projects to prove it works
self.fields['release_date'].widget.attrs["div_css"] = 'test'
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Replace 'div_css' in my example with 'class' and you'll get
'class="test"' in your output.
All these replies, and none of them have mentioned why your original
approach doesn't work.
When iterating through a form in your template, each field instance
returned is not a field from form.fields, it is a BoundField that
represents the corresponding field from form.fields.
The original field object is available in bfield.field . Therefore,
with your original code, you can do this in the template:
{% for bfield in form.visible_fields %}
<div class="{{ bfield.field.div_css }}" >
....
</div>
{% endfor %}
Cheers
Tom