1

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

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

在此处输入图像描述

当我在生产中测试相同的东西时,我得到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

4

0 回答 0