[Python] Jinja2 Using images in HTML

Discussão em 'Python' iniciado por Stack, Março 4, 2025.

  1. Stack

    Stack Membro Participativo

    I wasted a lot of time to find out what is wrong. I need your help now. I want to render template with image from my filesystem. But it is not working. Path - string that contains file name

    @app.route('/', methods=['GET'])
    def main():

    return render_template('main.html',image = path)


    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>test</title>
    </head>
    <body>
    <h2></h2>
    <form method="post" enctype="multipart/form-data" action="/uploader">
    <input type="file" name="file">
    <button type="submit">Upload</button>
    </form>
    <img src={{ url_for('static', filename = image) }} >//i can't figure how to change this to use {{image}}
    </body>
    </html>

    Continue reading...

Compartilhe esta Página