Don’t include paths like ../static/something.jpg in you templates.

Instead use Flask’s url_for function do generate these links dynamically:

<img src="{{ url_for('static', filename='red.png') }}" alt="redKing" width=65 height=65>

If you moved your resources dir into the static dir, you could then do:

<a href="{{ url_for('static', filename='resources/regolamento2019-2020.pdf') }}" download="Regolamento_2019_2020.pdf">Click</a>

Hovever to stick with the current location of your resources directory, you could write a custom route (as per the example here) like:

from flask import send_from_directory

@app.route('/resources/<path:filename>')
def download_file(filename):
    return send_from_directory('resources',
                               filename, as_attachment=True)

Then include that within your template as:

<a href="{{ url_for('download_file', filename='regolamento2019-2020.pdf') }}">Click</a>

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top