django上载映像在验证时出现InMemoryUploadedFile错误

django上载映像在验证时出现InMemoryUploadedFile错误,django,image,upload,Django,Image,Upload,我正在尝试制作一个上传图像表单。但它在ym形式的成功清除时崩溃(get'InMemoryUploadedFile'对象没有属性'get') 我的表格是干净的: from django.template.defaultfilters import filesizeformat from django.utils.translation import ugettext_lazy as _ from django.conf import settings def clean(self): c

我正在尝试制作一个上传图像表单。但它在ym形式的成功清除时崩溃(get'InMemoryUploadedFile'对象没有属性'get')

我的表格是干净的:

from django.template.defaultfilters import filesizeformat
from django.utils.translation import ugettext_lazy as _
from django.conf import settings

def clean(self):
    content = self.cleaned_data['avatar']
    content_type = content.content_type.split('/')[0]
    if content_type in settings.CONTENT_TYPES:
        if content._size > settings.MAX_UPLOAD_SIZE:
            raise forms.ValidationError(_('Please keep filesize under %s. Current filesize %s') % (filesizeformat(settings.MAX_UPLOAD_SIZE), filesizeformat(content._size)))
    else:
        raise forms.ValidationError(_('File type is not supported'))
    return content
我的设置属性:

MAX_UPLOAD_SIZE = 1310720
CONTENT_TYPES = ['image']
这些错误工作正常。但当没有找到ValidationError时,我会得到内存中的错误。
我做错了什么?

您从
def clean()
返回了
self.cleaned_数据['avatar']
,该数据应该是
def clean_avatar()
clean()
无论如何都应该返回整个
cleaned_数据