【发布时间】:2013-07-08 02:15:43
【问题描述】:
我有一个生成图像的程序。现在我想用 Flask 让其他用户可以访问这张图片,但是我无法用下面的代码显示这张图片:
#!/usr/bin/python2
#coding: utf-8
from flask import *
app = Flask(__name__)
#app.run(host='0.0.0.0')
@app.route('/')
def index():
return render_template('hello.html')
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0')
我的模板 hello.html 是:
<!doctype html>
<title>Hello from Flask</title>
<h1>Hello World!</h1>
<img src="./weather-plot.png">
当我运行这个程序并访问页面时,我看到了这个:
192.168.0.61 - - [10/Jul/2013 10:22:09] "GET / HTTP/1.1" 200 -
192.168.0.61 - - [10/Jul/2013 10:22:09] "GET /weather-plot.png HTTP/1.1" 200 -
在我的浏览器中,我看到了标题,但没有看到图片。怎么了?
顺便问一下,有没有更好的方法来显示没有其他任何东西的图片?也许我不必使用模板?
【问题讨论】:
-
嗯,我认为标题标签放错了位置。它是标题的一部分,而不是正文部分。
-
@reporter:
head和body元素的 标签 是可选的,因此上面的 HTML 没有任何问题。