【发布时间】:2011-09-30 15:11:42
【问题描述】:
我在下面有一个自定义的清理方法:
def clean_image(self):
image = self.cleaned_data['image']
if image:
from django.core.files.images import get_image_dimensions
w, h = get_image_dimensions(image)
if not image.content_type in settings.VALID_IMAGE_FORMATS:
raise forms.ValidationError(u'Only *.gif, *.jpg and *.png images are allowed.')
if w > settings.VALID_IMAGE_WIDTH or h > settings.VALID_IMAGE_HEIGHT:
raise forms.ValidationError(u'That image is too big. The image needs to be ' + str(settings.VALID_IMAGE_WIDTH) + 'px * ' + str(settings.VALID_IMAGE_HEIGHT) + 'px (or less).')
return image
问题场景是这样的:
图片已上传。我现在想使用使用 ImageField 小部件出现的复选框来清除它。提交表格以明确这一点时,不会发生。
如果我删除了我的自定义清理方法,那么 clear 确实有效。因此我猜我的方法做错了。
【问题讨论】:
-
尝试取消缩进返回,使其与 if 语句内联,即它始终返回数据。
-
django-vimage 3rd-party 包怎么样?我刚刚创建了它并尝试解决这种情况。问候:)
标签: django