How do I add an extra attribute in my input for Django forms?
Add the attrs
keyword argument to your field constructor's widget
, and include write your attribute in there:
address = forms.TextField(widget=forms.TextInput(attrs={'placeholder': 'username'}))
If you want to see it in action, take a look at django-registration's forms.py.
Alternatively, you can use the http://pypi.python.org/pypi/django-widget-tweaks app:
{% load widget_tweaks %}
...
{{ theform.address|attr:"placeholder:username" }}