gpt4 book ai didi

python - “WSGIRequest”对象没有属性 'FILE'

转载 作者:行者123 更新时间:2023-12-01 02:39:48 27 4
gpt4 key购买 nike

我想制作一个应用程序,它可以获取 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com