У объекта 'InMemoryUploadedFile' нет атрибута 'to_excel' - Django
У меня проблема, у меня есть этот скрипт на python pandas и он отлично работает, мне нужно было сделать так, чтобы обработать pandas весь документ, но теперь, когда я пытаюсь вставить в django, я получаю эту ошибку... Есть идеи?
Ошибка
AttributeError at /
'InMemoryUploadedFile' object has no attribute 'to_excel'
Request Method: POST
Request URL: http://127.0.0.1:8000/
Django Version: 3.2.6
Exception Type: AttributeError
Exception Value:
'InMemoryUploadedFile' object has no attribute 'to_excel'
Exception Location: /home/user/django-pandas/myapp/views.py, line 50, in my_view
Python Executable: /usr/bin/python
Python Version: 3.9.6
Это views.py
def my_view(request):
if request.method == "POST":
form = DocumentForm(request.POST, request.FILES)
if form.is_valid():
newdoc = request.FILES['docfile'
dfs = pd.read_excel(newdoc, sheet_name=None, index_col=[0])
with pd.ExcelWriter('output_.xlsx') as writer:
for name, df in dfs.items():
#pandas code
# after pandas code
output = io.BytesIO()
writer = pd.ExcelWriter(output, engine='xlsxwriter')
newdoc.to_excel(writer, index=False) #error (this is line 50)
writer.save()
output.seek(0)
response = HttpResponse(output,
content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
response['Content-Disposition'] = 'attachment; filename=%s.xlsx' % 'Download'
return response
else:
form = DocumentForm()
return render(request, 'list.html', {'form': form})
Заранее спасибо!