If django uses openpyxl to load_workbook(), an error occurs.

Asked 2 years ago, Updated 2 years ago, 69 views

I'm trying to load the xlsx file using python django and work on it

The py file and filename.xlsx are in the same folder.

In python environment

import openpyxl

wb = openpyxl.load_workbook('filename.xlsx')
sheet = wb.active

There was no problem with this way

If you put the same sauce in django,

archive = ZipFile(filename, 'r', ZIP_DEFLATED)

File "/Users/tevian/.pyenv/versions/3.5.1/lib/python3.5/zipfile.py", line 1009, in init

self.fp = io.open(file, filemode)

FileNotFoundError: [Errno 2] No such file or directory: 'filename.xlsx'

This error message appears.

django openpyxl error

2022-09-22 20:38

1 Answers

I couldn't find the file because I was looking for the file based on django's BASE_DIR path.

Simply forms.The result of os.getcwd() is different when running with py and when django is running server


2022-09-22 20:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.