python - Fail to show an image using Flask -
i want show image in homepage of python web application. far wrote following program:
my directories , files
mywebapp/ app/ __init__.py views.py templates/ home.html static/ desert.jpg run.py __init__.py
from flask import flask app = flask(__name__) app import views views.py
from app import app flask import render_template 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 run run.py, receive following internal server error:
what's wrong?
that's not correct syntax render_template function. need use keyword arguments:
return render_template('home.html', imag=imag, tle=tle) 
Comments
Post a Comment