Skip to content Skip to sidebar Skip to footer

How Can I Load Svg File Into My Python Flask Page?

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

Solution 1:

this did the trick:

from flask import Markup

@app.route('/map_test/')deftest():
   svg = open('file.svg').read
   return render_template('test.html', svg=Markup(svg))

Solution 2:

from flask import Flask, render_templateapp= 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><htmllang="en"><body><imgsrc="{{ img }}"></body></html>

put your svg file in dir called static

Post a Comment for "How Can I Load Svg File Into My Python Flask Page?"