0

Images not working in Flask

My code is not working for saving image and not showing in webpage at all. I tried other codes similar and that are working. Folder structure: static: images templates: index.html app.py However if I write the code of 2nd function disp in Home function it is working. https://code.sololearn.com/Ww5qvN523eox/?ref=app https://code.sololearn.com/cPbtuNSuCZ9P/?ref=app

6th Dec 2020, 8:34 AM
harshit
harshit - avatar
8 Réponses
+ 5
harshit What you are referring for - {{ name }} <img src={{ url }}> Here? Am unable to understand that you are trying to connect both files in sololearn? While there isn't a definite path for that!
6th Dec 2020, 9:30 AM
Piyush
Piyush - avatar
+ 1
You also need to pass named arguments name and url into render_template() at line 15 of your app.py
6th Dec 2020, 12:00 PM
Gordon
Gordon - avatar
0
Why not just use the image url directly in the HTML (<img src="/static/images/crypto_std.png">) Or better still...use url_for. Use url_for("static", filename=.....) Google how to use url_for Always use url_for static files. It works better. Happy Coding 😀
6th Dec 2020, 10:12 AM
Tomiwa Joseph
Tomiwa Joseph - avatar
0
Gordon that will work. But many a places I have seen passing arguments other than in home function and no arguments in home function. But I don't know in my case why that is not working. https://towardsdatascience.com/how-to-easily-deploy-machine-learning-models-using-flask-b95af8fe34d4
6th Dec 2020, 2:01 PM
harshit
harshit - avatar
0
Tomiwa Joseph using directly url in src will work but I don't know why my 2nd function is not rendering anything including simple text and images but the home function is working fine.
6th Dec 2020, 2:11 PM
harshit
harshit - avatar
0
Piyush[21 Dec❤️] not for sololearn. Just to give an example. It is for Flask.
6th Dec 2020, 2:12 PM
harshit
harshit - avatar
0
The home route can handle both the get and post request. I really don't see a reason for the disp route. For the image, use this: <img src="{{ url_for('static', filename='images/crypto_std.png') }}">
6th Dec 2020, 2:42 PM
Tomiwa Joseph
Tomiwa Joseph - avatar
0
Tomiwa Joseph what is the benefit of url_for when simply also it is functioning ?
6th Dec 2020, 2:55 PM
harshit
harshit - avatar