密码表单样式在Django中不起作用

z3yyvxxp  于 2023-05-23  发布在  Go
关注(0)|答案(1)|浏览(103)

我试图改变基本的标志形式,并做了以下风格

from django import forms
from django.contrib.auth.forms import UserCreationForm
from .models import Product
from userprofile.models import Customer
from django.forms import TextInput, EmailInput, PasswordInput
from django.contrib.auth.models import User

class CrateUserForm(UserCreationForm):
    class Meta:
        model = User
        fields= ['username', 'email', 'password1', 'password2',]
        widgets = {
            'username': forms.TextInput(attrs={
                'class': 'w-100 p-3 rounded-4 border border-success shadow',
                'placeholder': 'Exemplu1234',
            }),
            'email': forms.EmailInput(attrs={
                'class': 'w-100 p-3 rounded-4 border border-success shadow',
                'placeholder': 'exemplu@email.com',
            }),
            'password1': forms.PasswordInput(attrs={
                'class': 'w-100 p-3 rounded-4 border border-success shadow',
            }), 
            'password2': forms.PasswordInput(attrs={
                'class': 'w-100 p-3 rounded-4 border border-success shadow',
            }), 
        }

现在我的问题是,两个密码的字段没有改变,而其他两个做了。我怎样才能让它们工作?
我试图重新排序字段,但没有任何变化。

zzwlnbp8

zzwlnbp81#

您需要像这样覆盖两个密码字段,我认为它应该可以工作...
from django import forms
from django.contrib.auth.forms import UserCreationForm
from .models import Product
from userprofile.models import Customer
from django.forms import TextInput, EmailInput, PasswordInput
from django.contrib.auth.models import User

class CrateUserForm(UserCreationForm):
    password1 = forms.CharField(widget=forms.PasswordInput(attrs={'class': 'w-100 p-3 rounded-4 border border-success shadow'}))
    password2 = forms.CharField(widget=forms.PasswordInput(attrs={'class': 'w-100 p-3 rounded-4 border border-success shadow',}))
    class Meta:
        model = User
        fields= ['username', 'email', 'password1', 'password2',]
        widgets = {
            'username': forms.TextInput(attrs={
                'class': 'w-100 p-3 rounded-4 border border-success shadow',
                'placeholder': 'Exemplu1234',
            }),
            'email': forms.EmailInput(attrs={
                'class': 'w-100 p-3 rounded-4 border border-success shadow',
                'placeholder': 'exemplu@email.com',
            }),
            
        }

相关问题