djangosnippets.org: Latest snippets posted by jmsfwkhttps://djangosnippets.org/users/jmsfwk/2016-05-26T06:19:45.086713-05:00jmsfwkClass based FileTypeValidator
2016-05-26T06:19:45.086713-05:00jmsfwkhttps://djangosnippets.org/snippets/10570/<p>A validator to check that an uploaded file has one of the given extensions.</p>
<p>It <strong>does not</strong> check the MIME type/ any file contents.</p>
<pre><code>from django import forms
from .validators import FileTypeValidator
class UploadForm(forms.Form):
csv_file = forms.FileField(label="Upload file",
validators=[FileTypeValidator(('csv', 'txt'))])
</code></pre>
Freely redistributable