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.MimetypeValidatorThis validator is used to check mime type/ content type of the uploaded file. This validator checks file header information to check mime type on
FileFieldexample
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.FileSizeValidatorThis validator is useful for validating file size in
FileFieldexample
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)])
Metadata
Release files for django-validators 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django-validators-1.0.1.tar.gz | 2.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_validators-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.1 kB
Release files / django-validators-1.0.1.tar.gz
| Download URL | django-validators-1.0.1.tar.gz |
|---|---|
| Size | 2.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9f8d7502380eef1914decd6d7930b644036fc568381aab65e1afeb89515aa0a3
|
|
BLAKE2b-256 checksum How to use checksums |
90317996446474d8bebb254bda5bffe2c608310748d15b62fe58d49d114cba3c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / django_validators-1.0.1-py3-none-any.whl
| Download URL | django_validators-1.0.1-py3-none-any.whl |
|---|---|
| Size | 3.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0232118de8440840a3d1e316dd91029fa6c5a57615b8ddfba74a595eb15117bc
|
|
BLAKE2b-256 checksum How to use checksums |
6cc8fef5aee295373078eab4dfbe04a2afeab1a72f7f752c0f294b4834de1c60
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for django-validators 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.