无法解析['document']处的MultiValueDictKeyError

时间:2019-11-10 23:46:20

标签: python django

我想将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错误。谁能告诉我代码有什么问题吗?

0 个答案:

没有答案