Я действительно не уверен, почему я продолжаю получать ошибки, когда я использую open_workbook из xlrd ... идея в том, что я хочу создать веб-страницу, которая загружает файл Excel и открывает этот файл через мой код для обработки данных,Есть ли способ обойти это?
def upload(request):
if "GET" == request.method:
messages.warning(request, 'no file uploaded')
return render(request, 'uploadpage/upload.html', {})
else:
excel_file = request.FILES["excel_file"]
wb = xlrd.open_workbook(excel_file)
# iterating over the rows and
# getting value from each cell in row
sheet = wb.sheet_by_name("Summary")
#looping through each rows in a column to find the seller's info
# and storying the values in an array
seller_info = []
count = 1
cfirst, clast = 1,2
while (count < 6):
for colx in range(cfirst, clast):
count = count+1
seller_info.append(sheet.col_values(colx, start_rowx=count-1, end_rowx=count))
return render(request, 'uploadpage/upload.html', {"excel_data": seller_info})
Вот код переднего конца
<div id='upload-container' >
<span>
<h2>Upload Here</h2>
</span>
<div id='input'>
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
<input type="file" name="excel_file">
<div id='btn'>
<button type="submit">Upload File</button>
</div>
</form>
</div>
Это сообщение об ошибке я получаю
TypeError at /ожидаемый объект str, bytes или os.PathLike, не InMemoryUploadedFile Метод запроса: URL-адрес запроса POST: http://127.0.0.1:8000/ Версия Django: 2.2.5 Тип исключения: TypeError Значение исключения:
объект ожидаемого str, bytes или os.PathLike, а не InMemoryUploadedFile