Ebrahim Ghasemi
Ebrahim Ghasemi

Reputation: 6116

Fail to show an image using Flask

I want to show an image in the homepage of a python web application. So far I wrote the following program:

My directories and files

myWebApp/
    app/
        __init__.py
        views.py
    templates/
        home.html
    static/
        Desert.jpg
    run.py

__init__.py

from flask import Flask
app = Flask(__name__)
from app import views

views.py

from app import app
from flask import render_template
from flask import url_for

@app.route('/')
def root():
    imag = url_for ('static', filename = 'Desert.jpg')
    tle = "Hey"
    return render_template('home.html', imag,tle)

home.html

<html>
    <title>{{ tle }}</title>
    <body>
        <img src="{{ imag }}"/>
    </body>
</html>

run.py

from app import app
if __name__ == "__main__":
    app.run()

And when I run the run.py, I receive the following Internal Server Error:

enter image description here

What's wrong?

Upvotes: 1

Views: 517

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599460

That's not the correct syntax for the render_template function. You need to use keyword arguments:

return render_template('home.html', imag=imag, tle=tle)

Upvotes: 4

Related Questions