I want to upload an excel file to the server but I'm getting an error as MultiValueDictKeyError at ['document'] in the below mentioned code.
views.py
def index(request):
if request.method == 'POST':
uploaded_file = request.FILES['document']
print(uploaded_file.name)
print(uploaded_file.size)
return render(request, "polls/upload.html")
upload.html
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<input type="file" name="document">
<button type="submit">Upload</button>
</form>
I want to be able to upload the file but I'm getting an error as MultiValueDictKeyError at ['document']. Can anyone please tell me what is wrong with the code?