【发布时间】:2020-08-01 23:37:18
【问题描述】:
我的forms.py 中有以下表格。由于某种原因,username 字段 WORKS 和(两者)密码字段的 label 和 help_text 的覆盖都没有。
class CreateUserForm(UserCreationForm):
class Meta:
model = User
fields = ['username', 'password1', 'password2']
labels = {
'username': 'My Username Label',
'password1': 'My Password1 Label',
'password2': 'My Password2 Label',
}
help_texts = {
'username': 'My username help_text',
'password1': 'My password1 help_text',
}
渲染时,默认的 django 标签/help_texts 会显示密码字段:
Your password can’t be too similar to your other personal information.
Your password must contain at least 8 characters.
...
我也阅读了文档,并且有一条注释here(降低页面的绿色注释)似乎相关,但我不太明白。它提到了以声明方式定义的字段,我没有这样做。也不会解释为什么它适用于username 而不适用于password1。
【问题讨论】:
-
能否分享一下你的模板并查看代码
-
username是模型上的实际字段,因此 Meta 中的覆盖有效。password1是仅在表单上定义的字段,帮助文本是从密码验证设置中设置的验证器生成的。原来的 help_text 有什么问题?
标签: python django django-forms