0

I am building a flask questionnaire app, and the last feature is a button to download an excel spreadsheet with all the data. However, to download the file I need to specify a path. I thought it better to be a relative path (because once on a web server it should not access my libraries anymore) but I get the following error:

FileNotFoundError: [WinError 3] The system cannot find the path specified: 'c:\\Users\\me\\Desktop\\webApp\\website\\website\\templates\\downloads\\data.xlsx'

as you can see, the directory called 'website' is in it twice; I only have one called website, the absolute path is like this:

C:\\Users\\me\\Desktop\\webApp\\website\\templates\\downloads\\data.xlxs

This works fine in production, but can I use this in deployment as well? If not, what is a better alternative or how can I fix the double "//website" issue? Thanks in advance!

auth.py relevant code:

@auth.route('/downoad')
@login_required
def download_file():
    from .funcs import download_excel
    path = download_excel()
    return send_file(path, as_attachment=True)

funcs.py relevant code:

def download_excel():
    file = 'website\\templates\\downloads\\data.xlsx'
from datetime import datetime
    from openpyxl import Workbook, load_workbook
    from . import db
    dataset = AddEnqueteForm.query.all()
    workbook = load_workbook(file)
    sheet = workbook.active

    workbook.save(filename=file)
    return file

I added "\website" because the app is ran from main.py, which is outside the website directory

directory structure

Veztar
  • 27
  • 1
  • 7

0 Answers0