3

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)

and test.html:

{% block content %}
<section>
    {{ svg }}
</section>
{% endblock %}

....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?

MrSolid51
  • 307
  • 1
  • 7
  • 17

2 Answers2

3

this did the trick:

from flask import Markup

@app.route('/map_test/')
def test():
   svg = open('file.svg').read
   return render_template('test.html', svg=Markup(svg))
MrSolid51
  • 307
  • 1
  • 7
  • 17
-2
from flask import Flask, render_template

app = Flask(__name__)


@app.route('/')
def hello_world():
   img = './static/download.svg'

   return render_template('index.html', img=img)


if __name__ == '__main__':
   app.run()

index.html

<!DOCTYPE html>
<html lang="en">
<body>
<img src="{{ img }}">
</body>
</html>

put your svg file in dir called static

Nihal
  • 5,262
  • 7
  • 23
  • 41
  • 2
    umm... I want my svg element to be dynamic, that's why i've been trying to load the full svg element in... this'll get me to load my svg file as pictures but won't allow me to dynamically change the elements. – MrSolid51 Jun 14 '18 at 08:01