Django-Django的图片字段默认支持/不支持哪些文件类型? [英] Django - Which file types does Django's image field support / not support by default?

查看:71
本文介绍了Django-Django的图片字段默认支持/不支持哪些文件类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了所有这些文章,其中涉及如何限制Django的imagefield仅接受某些文件类型",但是我还没有找到Django的imagefield默认支持/不支持的所有文件类型的列表./p>

是否存在Django的imagefield支持/默认不支持的文件类型列表?还是Django的imagefield允许提交任何文件类型?

(django将允许用户在图像字段中上载.pdf,.psd,.doc等文件,还是会引发错误?)

解决方案

Django的 ImageField 需要第三方软件包Pillow(或PIL,但不赞成使用该软件包).依靠这些软件包来验证文件确实是映像.这不取决于文件扩展名,而是取决于文件本身的内容.

如果您想知道是否支持某种类型的文件,则应查明您使用的是哪个版本的Pillow/PIL,并查看相应的文档.

I see all these posts which talk about 'how to limit Django's imagefield to only accept certain file types' but I am yet to find a list of all the file types which Django's imagefield supports / doesn't support by default.

Is there a list of file types which Django's imagefield supports / doesn't support by default? Or does Django's imagefield allow any filetype to be submitted?

(Will django allow users to upload .pdf, .psd, .doc etc. files in an imagefield or will it raise an error?)

解决方案

Django's ImageField requires the third-party package Pillow (or PIL, but support is deprecated). It depends on these packages to verify that a file is indeed an image. This is not dependant on the file extension, but on the content of the file itself.

If you want to know if a certain type of file is supported, you should find out which version of Pillow/PIL you are using, and check the corresponding documentation.

这篇关于Django-Django的图片字段默认支持/不支持哪些文件类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆