我想将excel文件上传到服务器,但是在下面提到的代码中的['document']处出现MultiValueDictKeyError错误。
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>
我希望能够上传文件,但是在['document']处出现MultiValueDictKeyError错误。谁能告诉我代码有什么问题吗?