python端
#傳遞resultant給html
@app.route('/resultShapeNchange')
def shapeNchange():
resultant = searchShapeNchange.return_img_stream("./static/photo/test.jpg")
#searchSapeNchange返回的結果,也就是resultant存放的數據是['/static/airplanes/image_0014.jpg', '/static/airplanes/image_0016.jpg', '/static/airplanes/image_0018.jpg', '/static/airplanes/image_0021.jpg', '/static/airplanes/image_0048.jpg']
return render_template('resultShapeNchange.html', resultant = resultant)
對應的resultShapeNchange.html,不能直接通過
<img src="{{ resultant[0] }}" />
來接受數據,這樣在前端會顯示
而是要根據http://127.0.0.1:5000/來給圖片url
即
<img src="{{ 'http://127.0.0.1:5000'+resultant[0] }}" />
此時圖片顯示正常
顯示多張圖片:
<img src="{{ 'http://127.0.0.1:5000'+resultant[0] }}" />
<img src="{{ 'http://127.0.0.1:5000'+resultant[1] }}" />
<img src="{{ 'http://127.0.0.1:5000'+resultant[2] }}" />
<img src="{{ 'http://127.0.0.1:5000'+resultant[3] }}" />
總結:向前端返回的圖片地址是服務器所在的地址,也就是前端界面上的端口,而直接通過後臺的地址會導致圖片顯示錯誤