我想在上传之前检查文件类型:
content = self.cleaned_data['picture']
content_type = content.content_type.split('/')[0]
当我上传图片时出现错误:
'NoneType' object has no attribute 'content_type'
这里可能出了什么问题?
imghdr.what https://docs.python.org/3/library/imghdr.html#imghdr.what如果图像有效,将返回图像格式为字符串(gif、png 等),或者None
否则。
Usage:
import imghdr
imghdr.what(value)
在上面的例子中value
可以是文件(类)对象或文件名。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)