How do I serve a static SVG file with Flask? How do I serve a static SVG file with Flask? flask flask

How do I serve a static SVG file with Flask?


There is a mistake in your mime type. The correct one is image/svg+xml (note the lack of the ā€˜sā€™).

import mimetypesmimetypes.add_type('image/svg+xml', '.svg')#                        ^ no s


A easy (but hacky) way is to add a new route just for svgs:

@app.route('/static/<svgFile>.svg')def serve_content(svgFile):    return file('static/'+svgFile+'.svg').read()