Hello, I'm using handle_uploaded_file in Django and it throws me the following error: MultiValueDictKeyError at / restore / "'file'"
Here I leave my code to see if you can help me and know what happens
This is the form.py
:
class Seleccion(forms.Form):
selec= forms.FileField()
This is the view.py
:
def restaurar(request):
if request.method == 'POST':
form = forms.Seleccion(request.POST, request.FILES)
handle_uploaded_file(request.FILES['file'])
return render(request, 'index.html')
else:
form = forms.Seleccion()
return render(request, 'salvas.html', {'form': form})
def handle_uploaded_file(f):
with open('upload_salva.sql', 'wb+') as destination:
for chunk in f.chunks():
destination.write(chunk)