Skip to content

Instantly share code, notes, and snippets.

@hersonls
Last active December 11, 2015 20:58
Show Gist options
  • Save hersonls/4658601 to your computer and use it in GitHub Desktop.
Save hersonls/4658601 to your computer and use it in GitHub Desktop.
Django: How to add placeholder in Django fields
from django import forms
class PlaceholderForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(PlaceholderForm, self).__init__(*args, **kwargs)
for field in self.fields.values():
new_attrs = {
'placeholder': field.label
}
field.widget.attrs.update(new_attrs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment