我想制作一个应用程序,它可以获取 Excel 文件并读取其内容,而不使用表单和模型。
我不断收到标题中的错误,我想知道错误是什么。
这是我的 HTML:
<div style="width: 800px; margin: 0 auto;">
<form enctype="multipart/form-data" action="." method='POST'> {% csrf_token %}
<input type="file" name="excelfile">
<input type="submit" value="Submit" />
</form>
</div>
这是我的观点:
def uploadexcelfile(request):
if request.method == "POST":
excel = request.FILE['excelfile'].read()
print('Opening workbook...')
wb = openpyxl.load_workbook(excel)
activesheet = wb.active
print(activesheet.title)
sheet = wb.get_sheet_by_name(activesheet.title)
print('Reading rows...')
for row in range(1, sheet.max_row + 1):
url = sheet['A' + str(row)].value
print(url)
else:
return render(request, 'uploadexcelfile.html')
最佳答案
我认为您正在寻找 request.FILES
而不是 request.FILE
。
关于python - “WSGIRequest”对象没有属性 'FILE',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45839867/