アップロードする前にファイルの種類を確認したい:
content = self.cleaned_data['picture']
content_type = content.content_type.split('/')[0]
写真をアップロードすると、エラーが発生します。
'NoneType' object has no attribute 'content_type'
ここで何が問題なのですか?
アップロードする前にファイルの種類を確認したい:
content = self.cleaned_data['picture']
content_type = content.content_type.split('/')[0]
写真をアップロードすると、エラーが発生します。
'NoneType' object has no attribute 'content_type'
ここで何が問題なのですか?
imghdr.what
画像が有効な場合は画像形式を文字列 (gif、png など) として返し、None
そうでない場合は返します。
使用法:
import imghdr
imghdr.what(value)
上記の例value
では、ファイル (のような) オブジェクトまたはファイル名のいずれかになります。