1

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?

2

1 Answer 1

4

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)
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.