1👍
✅
Any files in the form are put in request.FILES
by Django. Also one should make sure their form tag has the following set: enctype="multipart/form-data"
if they are submitting file data.
Your view should be like:
polloptions_form = AddpollForm()
if request.method == 'POST':
polloptions_form = AddpollForm(request.POST, request.FILES)
if polloptions_form.is_valid():
polloptions = polloptions_form.save(commit=True)
return redirect('home')
And your form tag when you are uploading files should be like:
<form method="post" enctype="multipart/form-data">
Source:stackexchange.com