未能使用Flask显示图像

问题描述:

我想在python Web应用程序的主页中显示图像。到目前为止,我写了下面的程序:未能使用Flask显示图像

我的目录和文件

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

当我运行run.py,我收到以下内部服务器错误

enter image description here

怎么了?

+0

你可以简单地''为 –

+0

更容易成为一个好主意,因为在http://flask.pocoo.org/docs描述激活调试模式解决问题的瓶/0.10/quickstart/#debug-mode。但确保它在生产中关闭。 –

这不是render_template函数的正确语法。您需要使用关键字参数:

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