django_auxilium.forms.files module¶
-
class
django_auxilium.forms.files.TypedFileField(*args, **kwargs)[source]¶ Bases:
django.forms.fields.FileFieldTyped FileField which allows to make sure the uploaded file has the appropriate type.
File type can be verified either by extension and/or mimetype.
This field accepts all the parameters as FileField, however in addition it accepts some additional parameters as documented below.
Examples
TypedFileField(ext_whitelist=['jpg', 'jpeg'], type_whitelist=['image/jpeg'])
Warning
If
use_magicis used, please make sure thatpython-magicis installed. This library does not require it by default.Parameters: - ext_whitelist (list, optional) – List of allowed file extensions. Note that each extension
should emit the first period. For example for filename
'example.jpg', the allowed extension should be'jpg'. - type_whitelist (list, optional) – List of allowed file mimetypes.
- use_magic (bool, optional) – If
type_whitelistis specified, this boolean determines whether to usepython-magic(based of top oflibmagic) to determine the mimetypes of files instead of relying on Django’sUploadedFile.content_type. Django does not take any real care to determine any accurately the mimetype so it is recommended to leave this parameter asTruewhich is the default value.
-
default_error_messages= {u'extension': u'File extension is not supported.', u'mimetype': u'File mimetype is not supported.'}¶
- ext_whitelist (list, optional) – List of allowed file extensions. Note that each extension
should emit the first period. For example for filename