后端
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2019-08-29 15:06
# @Author : Xinru
from flask import Flask,render_template,url_for
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
# return url_for('static', _external=True, filename='img/ww.png')
@app.route('/uu/')
def uu():
context = {
'imgurl':'/static/img/img1.jpg',
'age':2
}
# return render_template('uu.html',imgurl='/static/img/ww.png')
return render_template('uu.html', **context)
if __name__ == '__main__':
app.run(debug=True)
网页插入图片
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>pthoto测试</title>
</head>
<body>
<p>方法一</p>
<img src="/static/img/ww.png">
<p>方法二</p>
<img src = "{{ url_for('static', filename = 'img/ww.png') }}">
</body>
</html>
传参给前端
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>photo</title>
</head>
<body>
<p>方法一</p>
{{ imgurl }}
<p></p>
<img src="{{ imgurl }}">
</body>
</html>







网友评论