为什么小部件 EmailInput 样式不适用

Why widget EmailInput style doesn't apply

我正在尝试设置 Django 表单的样式,我可以将 class 应用到带小部件的 TextInputs,但对于电子邮件和密码它不适用。知道为什么吗? 另外,如何删除密码上面的文字?密码要求,不是 help_text

forms.py

class SignupForm(UserCreationForm):
    email = forms.EmailField()

    class Meta:
        model = User
        fields = ['email', 'first_name', 'last_name', 'password1', 'password2']
        widgets = {
            'email': forms.EmailInput(attrs={'class': 'forms-group__input'}),
            'first_name': forms.TextInput(attrs={'class': 'forms-group__input'}),
            'last_name': forms.TextInput(attrs={'class': 'forms-group__input'}),
            'password1': forms.PasswordInput(attrs={'class': 'forms-group__input'}),
            'password2': forms.PasswordInput(attrs={'class': 'forms-group__input'}),

        }

forms.html

        <form class="forms-group__form" method="POST" enctype="multipart/form-data">
    
        {% csrf_token %}
        {% for field in form %}
            {{ field.errors }} <br>
            <div class="forms-group__input-field">
    
                <label class="forms-group__label">{{ field.label_tag }}</label><br>
    
                {{ field }}<br>
    
                {% if field.help_text %}
                <p class="help">{{ field.help_text|safe }}</p>
                {% endif %}
    
            </div>
        {% endfor %}

    <div class="forms-group__button-div"><input class="button submit-button forms-group__button" type="submit" value="Update Profile"></div>

    </form>

以 class 形式 声明 的字段不会由 ModelForm 自动生成,因此在 [=12] 中为它们声明一个小部件=] Meta 的属性不起作用。您可以放弃在 class 中声明它并让它自动生成:

class SignupForm(UserCreationForm):
    <s>email = forms.EmailField()</s>
    ...

或者您可以在字段本身中为字段指定小部件:

class SignupForm(UserCreationForm):
    email = forms.EmailField(widget=forms.EmailInput(attrs={'class': 'forms-group__input'}))
    ...