Adding placeholders and initial values
There are two things our first manually built form had that our current Django form still does not have – placeholders and initial values. Adding placeholders is simple; they are just added as attributes to the widget constructor for the form field. This is similar to what we’ve already seen for setting the type of DateField
in our previous examples.
Here’s an example:
class ExampleForm(forms.Form): text_field = forms.CharField( widget=forms.TextInput(attrs={"placeholder": "Text Placeholder"}) ) password_field = forms.CharField( widget=forms.PasswordInput(attrs={"placeholder": "Password Placeholder"}) ...