Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis0
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
8 Respostas
+ 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!
+ 1
You also need to pass named arguments name and url into render_template() at line 15 of your app.py
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 š
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
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.
0
Piyush[21 Decā¤ļø] not for sololearn. Just to give an example. It is for Flask.
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') }}">
0
Tomiwa Joseph what is the benefit of url_for when simply also it is functioning ?