1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How to pass variables to a template HTML with Flask

Discussão em 'Python' iniciado por Stack, Novembro 24, 2025.

  1. Stack

    Stack Membro Participativo

    i'm currently learning Flask templates, but i can't undestand how to pass a variable to it. Example of my Python code:

    from flask import Flask

    app = Flask(__name__)

    @app.route('/')
    def home():
    return {"message":"on"}, 200

    @app.route('/user/<string:username>')
    def user_profile(username):
    return render_template('profile.html')


    My profile.html:

    <!DOCTYPE html>
    <html>
    <head>
    <title>Perfil</title>
    </head>
    <body>
    <h1>User: (username)</h1>
    </body>
    </html>

    Continue reading...

Compartilhe esta Página