I want to make an app that takes excel file and reads its content, without using form and models.
I keep getting the error in the title and I would to know what the error is.
This is my 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>
This is my view:
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')
I think you're looking for request.FILES
instead of request.FILE
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With