[Python] Markdown not showing images from local Flask site

Discussão em 'Python' iniciado por Stack, Agosto 13, 2025.

  1. Stack

    Stack Membro Participativo

    I have created a Flask site to serve static images. It is http only site and not https

    I can view these images (mainly svg but also a png file for testing) in the browser. However when I try to link them in a markdown file, they are not visible. I am able to link to external images in the markdown and view them but not the ones from my site.

    I am using the following code to view the images

    Method 1

    @app.route('/image/<path:req_path>')
    def send_image(req_path):
    base_dir = <folder name>
    abs_path = os.path.join(base_dir, req_path)
    if not os.path.exists(abs_path):
    return abort(404)
    if os.path.isfile(abs_path):
    if abs_path.endswith(".svg"):
    return send_file(abs_path, mimetype='image/svg+xml')
    else:
    return send_file(abs_path)
    return abort(404)


    Method 2

    @app.route('/badge/<path:filepath>')
    def send_img(filepath):
    return render_template('badges.html', badge_path=filepath)


    badges.html as follows

    <!DOCTYPE html>
    <html>
    <body>
    <img src="{{url_for('static', filename=badge_path)}}" />
    </body>
    </html>


    In both instances, the image is viewable in the browser but not visible in the markdown - I believe the paths etc are correct because I can ctrl+click the path and it is viewable in the browser.

    I want to know why Markdown is unable to preview the images.

    Created a markdown file and linked the images and expected the images to show up

    The markdown file was previewed in VS Code. Linking to external images, for e.g badges in shield.io / github content works fine and is viewable.

    For e.g. The following two statements show the image in the preview mode

    ![A mushroom-head robot drinking bubble tea](https://raw.githubusercontent.com/Codecademy/docs/main/media/codey.jpg)

    <img src="https://raw.githubusercontent.com/Codecademy/docs/main/media/codey.jpg" />

    <img src="https://img.shields.io/badge/Signal-%23039BE5.svg?&style=for-the-badge&logo=Signal&logoColor=white" />

    ![Test](https://img.shields.io/badge/Signal-%23039BE5.svg?&style=for-the-badge&logo=Signal&logoColor=white)


    The below statements do not work

    ![What!!!](http://10.200.40.182:5050/badge/all_badges/test.png)

    <img src="http://10.200.40.182:5050/badge/all_badges/test.png" />


    Even though clicking on the link / pasting the link + enter shows the image in the browser

    Continue reading...

Compartilhe esta Página