From 12b4280444b58c94197255655e284e4103fe00a9 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Sat, 26 Mar 2016 22:09:08 +0200 Subject: Fixed #21548 -- Added FileExtensionValidator and validate_image_file_extension. --- docs/ref/validators.txt | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'docs/ref') 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 + `_. -- cgit v1.3