How to limit file types on file uploads for ModelForms with FileFields?

后端 未结 7 773
星月不相逢
星月不相逢 2020-12-02 23:31

My goal is to limit a FileField on a Django ModelForm to PDFs and Word Documents. The answers I have googled all deal with creating a separate file handler, but I am not sur

7条回答
  •  一向
    一向 (楼主)
    2020-12-02 23:51

    An easier way of doing it is as below in your Form

    file = forms.FileField(widget=forms.FileInput(attrs={'accept':'application/pdf'}))
    

提交回复
热议问题