Flask and .svg picture not show

Question:

I started to work with python – Flask and I found some problems which i didn’t solve.

When I want show picture in .svg format so it doesn’t show in flask but when i open html file (index.html) in for example Firefox it showed!
Code in Flask template:

when i show source code (in flask server) it is logo. Link /static/img/logo-landing.svg is found but image doesn’t show. It show only alt (‘logo’)

I don’t know what is wrong. I was use google full last night.
Thanks Mike

Answers:

You have to serve your svg-images with Content-Type image/svg+xml.

Answered By: Daniel
from flask import send_file

@app.route('/svg_returned_endpoint', methods=['POST'])
def svg_returned_endpoint():
    # HTML version
    # this gets the json object from the user
    json_obj = {'input_1': request.values['input_1']}
    input_1_item = json_obj["input_1"]
    
    # normal endpoint version
    # this gets the json object from the user
    json_obj = request.get_json(force=True)
    input_1_item = json_obj["input_1"]
    
    ####
    ## Your Actual function/model Code Goes Here
    ####

    filename = 'YOUR_SAVED_IMAGE.svg'
    
    return send_file(filename, mimetype='image/svg+xml')
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.