【发布时间】:2011-12-26 05:07:39
【问题描述】:
我试过了:
self.data['uploaded_file'].content_type
但是,这会给出一个错误,指出该对象缺少 content_type 属性。
关于为什么的任何想法?谢谢。
在 Django 表单中验证文件类型的最佳方法是什么?
【问题讨论】:
标签: django django-forms django-file-upload
我试过了:
self.data['uploaded_file'].content_type
但是,这会给出一个错误,指出该对象缺少 content_type 属性。
关于为什么的任何想法?谢谢。
在 Django 表单中验证文件类型的最佳方法是什么?
【问题讨论】:
标签: django django-forms django-file-upload
content_type 属性仅存在于request.FILES 中包含的UploadedFile 实例上;您需要从中获取内容类型,或使用magic 从原始文件数据中获取。
【讨论】:
你怎么知道一个文件是二进制文件还是文本或其他东西? 也许使用文件扩展名是一种方法,但并不总是有意义。
【讨论】: