我想在 python web 应用程序的主页中显示图像。到目前为止,我编写了以下程序:
我的目录和文件
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>
运行.py
from app import app
if __name__ == "__main__":
app.run()
当我运行 run.py
时,我收到以下内部服务器错误:
怎么了?
最佳答案
这不是 render_template
函数的正确语法。您需要使用关键字参数:
return render_template('home.html', imag=imag, tle=tle)
关于python - 使用 Flask 显示图像失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31381891/