Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

limiting file extension in django form file upload

I have forms.Form in django. In this form there is a forms.FileField. This field is rendered in html as

<input id="id_upload-loaded_file" name="upload-loaded_file" type="file">

I need to add accepted files only with ".zip" extension so that form will be rendered as

<input id="id_upload-loaded_file" name="upload-loaded_file" type="file" accept=".zip">

How can I add accepted file extension attribute in django?

like image 283
zenprogrammer Avatar asked Oct 15 '25 17:10

zenprogrammer


1 Answers

This is how I did it:

zip_file = forms.FileField(label='Select zip file', widget=forms.FileInput(attrs={'accept': '.zip'}))
like image 177
zenprogrammer Avatar answered Oct 18 '25 06:10

zenprogrammer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!