user6127744
user6127744

Reputation:

How to restrict users to upload only doc and pdf formats in FileField in django?

I am working on a tutors website so tutors have to upload their resumes So I want to restrict them to upload only doc or pdf format resume through FileField in Django Models.

Upvotes: 1

Views: 1619

Answers (2)

user6127744
user6127744

Reputation:

def validate_file_extension(value):
        import os
        ext = os.path.splitext(value.name)[1]
        valid_extensions = ['.pdf','.doc','.docx']
        if not ext in valid_extensions:
            raise ValidationError(u'File not supported!')

Upvotes: 1

OnionFan
OnionFan

Reputation: 511

Try this solutions:

ExtFileField

python-magic

Upvotes: 0

Related Questions