forms.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:multiuploader 作者: vinaypost 项目源码 文件源码
def clean_file(self):

        content = self.cleaned_data[u'file']
        filename, extension = os.path.splitext(content.name)

        if self.check_extension:
            if re.match(self._options['acceptFileTypes'], extension, flags=re.I) is None:
                raise forms.ValidationError('acceptFileTypes')

        if self.check_content_type:
            content_type = magic.from_buffer(content.read(1024), mime=True)
            if content_type.lower() in self._options['allowedContentTypes']:
                if content._size > self._options['maxFileSize']:
                    raise forms.ValidationError("maxFileSize")
            else:
                raise forms.ValidationError("acceptFileTypes")

        return content
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号