Adding an attribute to the <input> tag for a django ModelForm field -


i have django model i'm displaying form using modelform. defaults work me part.

however, html <input ...> tags have 1 additional attribute, namely include placeholder attribute, following:

<input placeholder="{{field.label}}" ... /> 

what easiest way add attribute html? far can tell appears need implement own filter output field, seems overkill when want leave alone add 1 additional attribute.

see documentation

class authorform(modelform):     class meta:         model = author         widgets = {             'name': textinput(attrs={'placeholder': 'name'}),         } 

you create own widget derives textinput , includes placeholder attribute, , use widgets dictionary map fields new widget without specifying placeholder attribute every field.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -