Flask import static resources -


the problem: 404 when access static resources route other '/'.

i have image called volume.png in static folder in flask application. when route main page '/' using @app.route('/') finds image fine, , can display image when hit localhost:5000/static/images/volume.png. when use other link, example, '/s', says can't find image in s/static/images/volume.png. when create s directory , copy static directory it, 404 when type localhost:5000/s/static/images/volume.png. i've considered using flask-assets, there doesn't appear documentation or examples. what's way make sure routes have access static resources?

you need qualify path image in html (or css):

<!-- break in way describe --> <img src="static/images/volume.png" />  <!-- not --> <img src="/static/images/volume.png" />  <!-- nor (assuming using jinja template) --> <img src="{{ url_for('static', filename='images/volume.png') }}" /> 

the reason because of way user-agents required resolve relative paths uris (see section 5.1 of rfc 3968 details).

using static/images/volume.png results in following path @ /:

scheme://host.name/static/images/volume.png 

and following @ /s:

scheme://host.name/s/static/images/volume.png 

as have discovered. ensuring provide absolute path component (at least) resources, ensure browser merge provided path scheme , host.name, rather scheme, host.name , path.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -