hln*_*hln 2 python django image identification imghdr
我想在上传之前检查文件类型:
content = self.cleaned_data['picture']
content_type = content.content_type.split('/')[0]
Run Code Online (Sandbox Code Playgroud)
上传图片时出现错误:
'NoneType' object has no attribute 'content_type'
Run Code Online (Sandbox Code Playgroud)
这里有什么问题?
imghdr.what如果图片有效,则将以字符串(gif,png等)的形式返回图片格式None。
用法:
import imghdr
imghdr.what(value)
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,value可以是文件(类)对象或文件名。
| 归档时间: |
|
| 查看次数: |
1493 次 |
| 最近记录: |