Django:显示管理员验证错误的自定义错误消息 [英] Django: Display a custom error message for admin validation error
问题描述
这是我目前正在做的:
def clean_fields (自我,排除=无):
#验证
如果问题:
raise ValidationError({'field_name':错误消息})
不幸的是,所有这些都是在管理页面上打印出一个单独的验证消息,每个字符的值为 field_name
。
什么是正确的方式来显示我想要的错误消息?
不看,听起来管理员正在寻找一个可迭代的值作为 field_name
的值。尝试:
raise ValidationError({'field_name':[error message,]})
我认为管理员希望任何数量的验证消息与表单上的每个字段相关联。
I'm using Django 1.2.4. I have a model that has a field that needs to be validated. When validation fails, I'd like to display a custom error message to the user. Model editing is done in the admin interface.
This is what I'm doing currently:
def clean_fields(self, exclude=None):
# do validation
if problem:
raise ValidationError({'field_name': "error message"})
Unfortunately, all this does is print out a separate validation message on the admin page for each character in the value of field_name
.
What is the proper way to signal the error message I want?
Without looking, it sounds like the admin is looking for an iterable as the value for field_name
. Try:
raise ValidationError({'field_name': ["error message",]})
I think the admin expects any number of validation messages to be associated with each field on a form.
这篇关于Django:显示管理员验证错误的自定义错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!