我想知道我们如何自定义当我们在 Django 中内置的 UserCreationForm 的 password1 和 password2 字段中输入 2 个不同的密码时显示的错误消息。我试过这个
def __init__(self,*args, **kwargs):
super(CreateUserForm,self).__init__(*args, **kwargs)
self.fields['password2'].error_messages.update({
'unique': 'Type smtn here!'
})
我在这个过程中做错了吗?在我的模板中,这是错误消息的代码。
<span id="error">{{form.errors}}</span>
请告诉我是否有其他方法可以做到这一点。我正在使用模型表格。
class CreateUserForm(UserCreationForm):
class Meta:
model = User
fields = ['username','email','password1','password2']
def __init__(self,*args, **kwargs):
super(CreateUserForm,self).__init__(*args, **kwargs)
self.fields['password2'].error_messages.update({
'unique': 'Type smtn here!'
})