-1

I want to access the local file using a hyperlink from the web using Flask. My file directory and what I have tried is as follows.

File directory:

-Flask
     -static/
         --some js
     -template/
         --some HTML
     -logs/
         --log1.log
         --log2.log
         --...
     app.py

I access the file in HTML as

 localhost:port/logs/log1.log

But the web gives me a 404.

How could I access the file? I am not very sure about the route in Flask. Could you give me some reference?

Thanks.

Elegant Lin
  • 25
  • 2
  • 10

1 Answers1

1

You can use send_from_directory function in flask to send static files This might help you

@app.route('/logs/<path:filename>')
def download_file(filename):
    return send_from_directory("/logs/",
                               filename, as_attachment=True)
Rafa Guillermo
  • 14,474
  • 3
  • 18
  • 54
Deepam Patel
  • 190
  • 6