I have written an email form class in Django with a FileField. I want to check the uploaded file for its type via checking its mimetype. Subsequently, I want to limit file t
You can use django-safe-filefield package to validate that uploaded file extension match it MIME-type.
from safe_filefield.forms import SafeFileField class MyForm(forms.Form): attachment = SafeFileField( allowed_extensions=('xls', 'xlsx', 'csv') )