在生产中引发ValidationError时出现500内部服务器错误

时间:2012-11-23 16:17:07

标签: python django django-forms

我会尽量保持这个简单。我有一个自定义字段:

class CharExactLengthField(CharField):
    """ FormField to represent a CharField with an exact Length
    """
    def __init__(self, length=None, required=True, widget=None, label=None,
                 initial=None):
        self.length = length
        CharField.__init__(self, max_length=length, required=required,
                                 widget=widget, label=label, initial=initial)
    def clean(self, value):
        """ Clean for CharExactLengthField
        """
        super(CharExactLengthField, self).clean(value)
        if not self.required and value in EMPTY_VALUES:
            return None
        if self.length != len(value):
            raise ValidationError(
                'Require exactly %i characters' % self.length)
        return value

此字段以多种形式使用,但在此特定形式中,我只是测试此字段是否为空,因此它将回退到super(CharExactLengthField, self).clean(value)。在开发中测试时,我得到了正常的This field is required

enter image description here

当我在制作中测试同样的东西时,我得到Internal Server Error

ValidationError at /test/test/1/
[u'This field is required.']

Request Method: POST
Request URL:    http://smo/test/test/1/
Exception Type: ValidationError
Exception Value:    [u'This field is required.']
Exception Location: /usr/local/lib/python2.5/site-packages/django/newforms/fields.py in clean, line 78

有什么理由可以解决这个问题吗?为什么ValidationError仅在生产中抛出内部服务器错误?

注意:

如果你还没有注意到,那就是Django 0.96.5

0 个答案:

没有答案