diff options
| author | Berker Peksag <berker.peksag@gmail.com> | 2016-03-26 22:09:08 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-06-30 09:08:50 -0400 |
| commit | 12b4280444b58c94197255655e284e4103fe00a9 (patch) | |
| tree | 26640543f44e65800ae0fbb59004e9e7907bdf73 /docs | |
| parent | c9d0a0f7f47c8496a9d8b0cfda94e2ef118d9ab3 (diff) | |
Fixed #21548 -- Added FileExtensionValidator and validate_image_file_extension.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/validators.txt | 27 | ||||
| -rw-r--r-- | docs/releases/1.11.txt | 8 |
2 files changed, 34 insertions, 1 deletions
diff --git a/docs/ref/validators.txt b/docs/ref/validators.txt index 7c82f21605..417df517a4 100644 --- a/docs/ref/validators.txt +++ b/docs/ref/validators.txt @@ -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>`_. diff --git a/docs/releases/1.11.txt b/docs/releases/1.11.txt index 5bac7e0b0a..1d79b7ffca 100644 --- a/docs/releases/1.11.txt +++ b/docs/releases/1.11.txt @@ -192,6 +192,9 @@ Models <django.db.models.query.QuerySet.update_or_create>` and :meth:`~django.db.models.query.QuerySet.get_or_create`. +* :class:`~django.db.models.ImageField` now has a default + :data:`~django.core.validators.validate_image_file_extension` validator. + Requests and Responses ~~~~~~~~~~~~~~~~~~~~~~ @@ -237,7 +240,10 @@ URLs Validators ~~~~~~~~~~ -* ... +* Added :class:`~django.core.validators.FileExtensionValidator` to validate + file extensions and + :data:`~django.core.validators.validate_image_file_extension` to validate + image files. .. _backwards-incompatible-1.11: |
