如何将svg文件加载到我的python flask页面中? [英] how can I load svg file into my python flask page?
本文介绍了如何将svg文件加载到我的python flask页面中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我想将svg文件放入我的页面(而不是图像,作为xml元素)-像这样需要它,以便我可以动态更改页面中的元素.
So I want to put an svg file into my page(not as an image, as an xml element) - need it like this so I could dynamically change elements within the page.
我做了一个我认为可以做到的简单代码:
and I made a simple code that I thought it'll do:
@app.route('/map_test/')
def test():
svg = render_template('file.svg')
response = make_response(svg)
response.content_type = 'image/svg+xml'
return render_template('test.html', svg=response)
和test.html:
and test.html:
{% block content %}
<section>
{{ svg }}
</section>
{% endblock %}
....刚刚返回<响应126181字节[200 OK]>
而不是svg元素...
....which just returned <Response 126181 bytes [200 OK]>
instead of svg element...
那么...为了使它正常工作,我需要做什么?
so... what do I need to do in order to get this to work?
推荐答案
这可以解决问题:
from flask import Markup
@app.route('/map_test/')
def test():
svg = open('file.svg').read
return render_template('test.html', svg=Markup(svg))
这篇关于如何将svg文件加载到我的python flask页面中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文