Django adding placeholders to django built in login forms

后端 未结 5 551
灰色年华
灰色年华 2021-01-06 03:13

I\'m using django built-in login forms and i want to add placeholders to username and password.

My template:

<
5条回答
  •  抹茶落季
    2021-01-06 04:06

    In response to your comment on the other answer. You can subclass the the Authentication form.

    from django import forms
    from django.contrib.auth.forms import AuthenticationForm
    from django.forms.widgets import PasswordInput, TextInput
    
    class PlaceholderAuthForm(AuthenticationForm):
        username = forms.CharField(widget=TextInput(attrs={'placeholder': 'Email'}))
        password = forms.CharField(widget=PasswordInput(attrs={'placeholder':'Password'}))
    

    or see the other function that was put in this question. --> How can I override the django AuthenticationForm input css class?

提交回复
热议问题