Home>

I am writing a simple API for smart home control. I want to be able to get a picture by name (id)

class PictureShower (Resource):
    def get (self, name):
        return f '' '<
html >
<
img src= "{name}" >
<
/html >
'' ', 200

The file itself with the name lies in the root of the project, next to the file being launched. However, when requesting the desired address, instead of the rendered html, I get a line with it:

"<
html >
<
img src= \ "44751a70-6795-4c02-8a35-c10fa5d4cbe8.jpg \" >
<
/html >
"

This displays in the browser window, just in text. How to make the browser interpret it as an html page.

  • Answer # 1

    Used built in flask send file

    class PictureShower (Resource):
        def get (self, name):
            return send_file (name, mimetype= 'image /png')