![](/img/trans.png)
[英]Django query content_type by name not content_type_id
[英]django content_type of a image while testing
我想獲取圖像的內容類型,而我正在做
image = open(PATH_TO_IMAGE)
print(image.name.content_type)
它給我一個錯誤,說str對象沒有屬性content_type
如何獲取內容類型?
我正在測試中執行此操作,並且在我看來,我正在獲取圖像的content_type。 我可以將圖像傳遞到視圖,但不能給我內容類型
還沒有測試過,但是根據我的記憶,您可以使用內置的imghdr
模塊並使用print(imghdr.what(image))
來獲取圖像的格式類型
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.