I want to create a form to upload and save videos from iOS Safari, which supports the "accept" attribute of the input tag, for example:
<input type=file accept="video/*">
lets you shoot and upload new video or select a video file on the device.
I've looked at the Django docs at: https://docs.djangoproject.com/en/dev/ref/forms/fields/#django.forms.FileField
but don't see where I can specify the "accept" attribute on input. Is this possible? Can I create the input tag in the template and still use Django form processing to accept the file?
Easy. In your model form, just make sure the FileInput
widget gets created with the needed accept
HTML attribute:
from django import forms
class VideoForm(forms.ModelForm):
class Meta:
model = Video
exclude = []
widgets = {
'video_file': forms.FileInput(attrs={'accept': '.mov,video/quicktime'}),
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With