如何在Django模型表单的PasswordInput上应用占位符属性?

时间:2019-05-15 13:10:41

标签: python html django django-forms

我已经创建了一个自定义注册表格。 '占位符'属性适用于用户名和电子邮件。但这不适用于我提到的“ forms.PasswordInput”的password1和password2。

from django import forms
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from .models import CustomUser

class CustomUserCreationForm(UserCreationForm):

    class Meta(UserCreationForm):
        model = CustomUser
        exclude=()
        widgets = {'username': forms.TextInput(attrs={'placeholder':'Username','class':'inputData'}),
                   'email': forms.TextInput(attrs={'placeholder': 'Email', 'class': 'inputData'}),
                   'password1': forms.PasswordInput(attrs={'placeholder': 'Password', 'class': 'inputData'}),
                   'password2': forms.PasswordInput(attrs={'placeholder': 'Confirm Password', 'class': 'inputData'})}

0 个答案:

没有答案