Django validators used for commonly used validations
Project description
Django Validators
Django validators provides validator function that can be used with Django form fields and Django rest framework serializer fields
Installation
Install django-validators
using pip
pip install django-validators
Types of validators
File validators
-
Mime type validator
djangovalidators.validators.MimetypeValidator
This validator is used to check mime type/ content type of the uploaded file. This validator checks file header information to check mime type on
FileField
example
from djangovalidators.validators import MimetypeValidator # with django forms class DemoForm(forms.Form): CONTENT_TYPES = ('image/png', 'application/pdf', 'image/jpeg', 'image/jpg', 'image/tiff',) file_object = forms.FileField(validators=[MimetypeValidator(CONTENT_TYPES)]) # with django serializers class DemoSerializer(serializers.Serializer): CONTENT_TYPES = ('image/png', 'application/pdf', 'image/jpeg', 'image/jpg', 'image/tiff',) FILE_SIZE_IN_BYTES = 1024 * 1024 * 5 # ~5 Mib file_object = serializers.FileField(validators=[MimetypeValidator(CONTENT_TYPES)])
-
File size validator
djangovalidators.validators.FileSizeValidator
This validator is useful for validating file size in
FileField
example
from djangovalidators.validators import FileSizeValidator # with django forms class DemoForm(forms.Form): FILE_SIZE_IN_BYTES = 1024 * 1024 * 5 # ~5 Mib file_object = forms.FileField(validators=[FileSizeValidator(FILE_SIZE_IN_BYTES)]) # with django serializers class DemoSerializer(serializers.Serializer): FILE_SIZE_IN_BYTES = 1024 * 1024 * 5 # ~5 Mib file_object = serializers.FileField(validators=[FileSizeValidator(FILE_SIZE_IN_BYTES)])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-validators-1.0.1.tar.gz
.
File metadata
- Download URL: django-validators-1.0.1.tar.gz
- Upload date:
- Size: 2.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.5.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f8d7502380eef1914decd6d7930b644036fc568381aab65e1afeb89515aa0a3 |
|
MD5 | d282a14ce1de318808752c91f999b771 |
|
BLAKE2b-256 | 90317996446474d8bebb254bda5bffe2c608310748d15b62fe58d49d114cba3c |
File details
Details for the file django_validators-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: django_validators-1.0.1-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.5.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0232118de8440840a3d1e316dd91029fa6c5a57615b8ddfba74a595eb15117bc |
|
MD5 | 5f4aa6369a64a8958604ac941d5c1464 |
|
BLAKE2b-256 | 6cc8fef5aee295373078eab4dfbe04a2afeab1a72f7f752c0f294b4834de1c60 |