Skip to content
Advertisement

Flask url_for – incorrect static folder path

I’m trying to add an image to my quiz.html page with Flask using:

JavaScript

When I look at the page source, it’s interpreted as: http://127.0.0.1:5000/quiz/static/img/question-mark.png rather than:
http://127.0.0.1:5000/static/img/question-mark.png

Yet, my .css files and .js files load in quiz.html using the same syntax just fine. How can I get the correct static file path?

My current structure is:

JavaScript

app.py

JavaScript

Advertisement

Answer

You don’t need a Jinja script to write a static image source. Just write:

JavaScript

All the static resources are automatically served under /static.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement