将“此字段为必填项”替换为Django 管理中的消息

发布于 2024-09-15 18:00:33 字数 203 浏览 3 评论 0原文

有没有办法替换 django admin 中的默认错误消息。我正在使用自定义小部件,因此我有表单,我想知道是否有类似的内容:
field_1 = forms.Charfield(widget=X, error_messge='y')

我已经尝试添加 claen_field_1 方法,但看起来当字段为空时不会调用它。任何想法将不胜感激

is there a way to replace the default error message in django admin. I'm using custom widget so I have the form and I was wondering is there something like:
field_1 = forms.Charfield(widget=X, error_messge='y')

I already tried to add claen_field_1 method but it looks that it is not called when the field is empty. Any ideas will be appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

山田美奈子 2024-09-22 18:00:33

是的,实际上这是表单功能而不是管理功能;),您可以在任何地方使用它。

field_1 = forms.Charfield(widget=X, error_messages={'required': 'y'})

有关更多信息,请参阅 django 文档

yes there is and actually this is forms functionality and not admin functionality ;), you can use this anywhere.

field_1 = forms.Charfield(widget=X, error_messages={'required': 'y'})

for more information see the django docs

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文