我是ip:port
绑定到www.xxx.com/abc/
下,目录结构是这样的
static/
images/
test.jpg
templates/
index.html
app.py
然后我在index.html
里面调用<img src="images/test.jpg" width="100" height="100" alt="test"/>
还是无法显示图片,想请问下有什么办法解决吗?
upd1:
是不是因为我绑定的域名不是根目录导致路径解析错误?
upd2:
贴下我的代码
index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="generator" content="pandoc" />
<title></title>
<style type="text/css">code{white-space: pre;}</style>
</head>
<body>
<hr />
<ul>
<li>hello world</li>
</ul>
<p><code>print hello world</code></p>
<p><img src="../images/test.jpg" width="100" height="100" alt="test"/></p>
</body>
</html>
app.py
#!/usr/bin/env python
from flask import Flask
from flask import render_template
from flask import Flask, url_for
app = Flask(__name__)
@app.route('/deeptest/')
def index():
return render_template('index.html')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5050)
src='..images/test.jpg'
试试
src="../static/images/test.jpg"
不过最好 {{ url_for('static', filename='images/test.jpg') }}
用 {{ url_for('static', filename='images/test.jpg') }}
返回的就是图片路径
相对路径错了
改成
<img src="../images/test.jpg" width="100" height="100" alt="test"/>
试试
<img src="{{ url_for('static', filename='images/test.jpg') }}" width="100" height="100" alt="test"/>