管理 UserCreationForm 属性和字段
我是 Django 的新手,即使在彻底尝试找到这个问题的答案之后,我也找不到任何答案。 =/
我正在使用 UserCretionForm 创建我的用户,我想知道一些事情:
1 - 如何管理此表单的属性? (例如,我不想显示“必需。30 个字符...”或“输入与上面相同的密码,以进行验证。”之类的提示。)
2 - 我想让它显示其他自定义字段。我该怎么做呢? (请尽量弄清楚我必须在哪里编写您将向我展示的代码,因为我不是专家=D)。 (例如,在巴西,我们需要存储一些国家信息。这就是我需要这些字段的原因。)
提前致谢! (是)
I am new in Django and even after trying thoroughly to find an answer for this question, I couldn't find any. =/
I am using UserCretionForm to create my users and I wanted to know a couple of things:
1 - How can I manage this form's properties? (e.g. I don't want to show the tips like "Required. 30 charact..." or "Enter the same password as above, for verification.")
2 - I want to make it show other customized fields. How can I do it? (please, try to be clear where I have to write the codes you'll show me as I am not an expert =D ). (e.g. Here in Brazil we have some national info I need to store. That is why I need these fields.)
Thanks in advance! (Y)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更改默认验证器消息
您可以通过表单字段的
error_messages
参数更改默认验证器的错误消息。要了解每个字段存在哪些验证器,请检查此处:https:/ /docs.djangoproject.com/en/dev/ref/forms/fields/#built-in-field-classes
向现有表单添加新字段
如果要添加新字段,可以通过以下方式添加它们子类化(这只是Python)。
如果您继承
UserCreationForm
并向其中添加一个字段,您最终会得到一个新的表单类,其中仅包含原始字段和您的新字段。覆盖管理表单
如果您尝试覆盖管理站点默认使用的
UserCreationForm
,则必须为User< 注册一个新的
ModelAdmin
/代码> 现代。Changing the default validator messages
You can change the error messages for the default validators via the
error_messages
argument to a form field.To find out which validators exist per field, check here: https://docs.djangoproject.com/en/dev/ref/forms/fields/#built-in-field-classes
Adding new fields to an existing form
If you want to add new fields, you'd add them via subclassing (which is just python).
If you subclass
UserCreationForm
and add a field to it, you end up with a new form class that simply has the original's fields and your new ones.Overriding the admin form
If you are trying to override the
UserCreationForm
that the admin site uses by default, you'll have to register a newModelAdmin
for theUser
moder.