Skip to content

Instantly share code, notes, and snippets.

@timonweb
Created January 20, 2017 14:44
Show Gist options
  • Save timonweb/9459beedd98604d05e000cb129b75ef9 to your computer and use it in GitHub Desktop.
Save timonweb/9459beedd98604d05e000cb129b75ef9 to your computer and use it in GitHub Desktop.
Add attributes to form fields
from contact_form.forms import ContactForm
# My form is a child of ContactForm class provided by django_contact_form module
class MyContactForm(ContactForm):
def __init__(self, data=None, files=None, request=None,
recipient_list=None, *args, **kwargs):
super().__init__(data=data, files=files, request=request, recipient_list=recipient_list,
*args, **kwargs)
self.fields['name'].widget.attrs['placeholder'] = 'name'
self.fields['email'].widget.attrs['placeholder'] = 'e-mail'
self.fields['body'].widget.attrs['placeholder'] = 'message'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment