mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #21548 -- Added FileExtensionValidator and validate_image_file_extension.
This commit is contained in:
parent
c9d0a0f7f4
commit
12b4280444
6 changed files with 141 additions and 6 deletions
|
@ -279,3 +279,30 @@ to, or in lieu of custom ``field.clean()`` methods.
|
|||
``decimal_places``.
|
||||
- ``'max_whole_digits'`` if the number of whole digits is larger than
|
||||
the difference between ``max_digits`` and ``decimal_places``.
|
||||
|
||||
``FileExtensionValidator``
|
||||
--------------------------
|
||||
|
||||
.. class:: FileExtensionValidator(allowed_extensions, message, code)
|
||||
|
||||
.. versionadded:: 1.11
|
||||
|
||||
Raises a :exc:`~django.core.exceptions.ValidationError` with a code of
|
||||
``'invalid_extension'`` if the ``value`` cannot be found in
|
||||
``allowed_extensions``.
|
||||
|
||||
.. warning::
|
||||
|
||||
Don't rely on validation of the file extension to determine a file's
|
||||
type. Files can be renamed to have any extension no matter what data
|
||||
they contain.
|
||||
|
||||
``validate_image_file_extension``
|
||||
---------------------------------
|
||||
|
||||
.. data:: validate_image_file_extension
|
||||
|
||||
.. versionadded:: 1.11
|
||||
|
||||
Uses Pillow to ensure that the ``value`` is `a valid image extension
|
||||
<https://pillow.readthedocs.org/en/latest/handbook/image-file-formats.html>`_.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue