# EmailField placeholder in django form?

**URL:** <https://forum.djangoproject.com/t/emailfield-placeholder-in-django-form/7047>\
**Category:** Forms & APIs\
**Created:** [March 14, 2021, 11:45pm UTC](https://forum.djangoproject.com/t/emailfield-placeholder-in-django-form/7047 "2021-03-14T23:45:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mishomor](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mishomor/32/3846_2.png) [@mishomor](https://forum.djangoproject.com/u/mishomor)\
**Post date:** [March 14, 2021, 11:45pm UTC](https://forum.djangoproject.com/t/emailfield-placeholder-in-django-form/7047/1 "2021-03-14T23:45:51Z")

</div>

Hi everyone,

My first post, fingers crossed :). Just started learning django and need a help with setting “placeholder” value for the django form in email field. I figured how to remove “label”, but when I render the page label is gone as expected but placeholder is not there. Any suggestion is greatly appreciated!!

–models.py  
class TestModel(models.Model):  
email = models.EmailField()

–forms.py  
class TestForm(forms.ModelForm):  
class Meta:  
model = TestModel  
fields = [‘email’]  
labels = {  
‘email’: ‘’  
}  
widgets = {  
‘test’: forms.EmailField(widget=forms.EmailInput(attrs={‘placeholder’: ‘Email to’}))  
}

Cheers,  
Gordon

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 15, 2021, 12:38am UTC](https://forum.djangoproject.com/t/emailfield-placeholder-in-django-form/7047/2 "2021-03-15T00:38:34Z")

</div>

See the docs on [Overriding the default fields](https://docs.djangoproject.com/en/3.1/topics/forms/modelforms/#overriding-the-default-fields) for the format of the `widgets` entry in the Meta class.

---

<div class="post-metadata">

**Author:** ![mishomor](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mishomor/32/3846_2.png) [@mishomor](https://forum.djangoproject.com/u/mishomor)\
**Post date:** [March 15, 2021, 5:05am UTC](https://forum.djangoproject.com/t/emailfield-placeholder-in-django-form/7047/3 "2021-03-15T05:05:44Z")

</div>

Thank you for the quick response Ken. Unfortunately, I was not able to figure how to put a placeholder from the documentation provided above. I don’t think anything is wrong with my syntax as I am getting no error message. It’s just that placeholder is not shown.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 15, 2021, 12:00pm UTC](https://forum.djangoproject.com/t/emailfield-placeholder-in-django-form/7047/4 "2021-03-15T12:00:47Z")

</div>

Look at the example in the referenced documentation.

`widgets` is a dict where the key is the field name and the value is the widget to be used.

That’s not how you have your widgets dict defined.

---

<div class="post-metadata">

**Author:** ![mishomor](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mishomor/32/3846_2.png) [@mishomor](https://forum.djangoproject.com/u/mishomor)\
**Post date:** [March 16, 2021, 6:50am UTC](https://forum.djangoproject.com/t/emailfield-placeholder-in-django-form/7047/5 "2021-03-16T06:50:08Z")

</div>

This is how I understand that form should look as per documentation. I get no errors, the page loads fine but the email field has no placeholder value. What I am doing wrong here?

class TestForm(forms.ModelForm):

```
class Meta:
    model = TestModel
    fields = ['email']
    labels = {
        'email': '',
    }

    widgets = {
        'test': forms.EmailInput(attrs={'placeholder': 'email'})
    }
```

---

<div class="post-metadata">

**Author:** ![mishomor](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mishomor/32/3846_2.png) [@mishomor](https://forum.djangoproject.com/u/mishomor)\
**Post date:** [March 16, 2021, 6:53am UTC](https://forum.djangoproject.com/t/emailfield-placeholder-in-django-form/7047/6 "2021-03-16T06:53:20Z")

</div>

OMG, it was typo in my widget. I used ‘email’ as field name yet ‘test’ in widget. As soon as I corrected it is working fine. It’s weird that PyCharm got me no error messages when saved the forms.py despite me referencing field that’s not defined.

Thank you Ken!!

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 16, 2021, 12:15pm UTC](https://forum.djangoproject.com/t/emailfield-placeholder-in-django-form/7047/7 "2021-03-16T12:15:05Z")

</div>

> [@mishomor](#):
>
> It’s weird that PyCharm got me no error messages when saved the forms.py despite me referencing field that’s not defined.

That’s one of those items that makes sense once you understand what’s actually going on here.  
The widgets dict isn’t referencing a field, it’s a place to define what widgets get used for fields. If that definition isn’t used by a form then it’s just not-used. (Notice that the key is a string and not a field.)

And, strictly speaking, this is _not_ an error. It may not be what you wanted in this specific case, but there’s nothing fundamentally wrong with it and there are contexts where it would be right!

`<opinion>`I don’t rely upon editors to catch errors in Django. Yes, they’ll catch some, but there are so many aspects of Django that are “declarative” rather than “procedural” (very informal terms) that an editor _can’t_ catch them.`</opinion>`
