Validated File Field
Using ValidatedFilefield can you say which type of files are allowed
Before we go to the Validatedfilefield tutorial, let's first get acquainted with ValidatedFilefield parameters
Parameters
info
| Parameters | Type | Description |
|---|---|---|
| accept | str | The accept attribute takes as its value a comma-separated list of one or more file types, or unique file type specifiers, describing which file types to allow. See this guide for more familiarity |
| custom_css_class | str | A custom class to customize input |
| multiple | boolean | If you want to upload multiple files, set up to True |
How Use ValidatedFilefield?
To use ValidatedFilefield you must act as follows:
1.First, import the ValidatedFilefield to your Django forms as follows:
from django import forms
from file_validator.forms import ValidatedFileField
- In the next step we have to give it to our form as follows:
from django import forms
from file_validator.forms import ValidatedFileField
class TestForm(forms.Form):
test_file = ValidatedFileField(
accept='image/*', # => accept attribute
custom_css_class='your-custom-css-class', # => custom css class
multiple=True # => for upload Multiple Files
)