Skip to content

Instantly share code, notes, and snippets.

@agusmakmun
Last active February 2, 2016 17:25
Show Gist options
  • Save agusmakmun/7dfddeabd65ce824e02b to your computer and use it in GitHub Desktop.
Save agusmakmun/7dfddeabd65ce824e02b to your computer and use it in GitHub Desktop.
django filefield accept image/* and video/*

Original: http://www.twiola.com/en/questions/90/django-filefield-accept-image-and-video my django form have the input file type

class MediaForm(forms.Form):
    title = forms.CharField(max_lenght=256)
    media = forms.FileField()

the field for upload only images and video. But in browse i can select any file, example *.rar, *.xls and others files..

I find resolved input type file accept images, but how i can add the attribute accept="image/,video/" in django template??

my template

<form>
    {% csrf_token %}
    {{ form.title }}
    {{ form.media }}
    <input type="submit">
</form>

###Answered

media = forms.FileField(widget=forms.FileInput(attrs={'accept':'image/*,video/*'}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment