Application minimale
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route("/")
def accueil():
return "<h1>Bonjour !</h1>"
@app.route("/salut", methods=["GET", "POST"])
def salut():
nom = request.form.get("nom", "inconnu")
return render_template("salut.html", nom=nom)
Modèle
templates/salut.html :
<h1>Salut {{ nom }} !</h1>
<form method="post"><input name="nom"><button>Envoyer</button></form>Jinja échappe automatiquement les variables (protection XSS).
Lancer
pip install flask
flask --app app run --debugLe mode debug est réservé au développement. En production : un serveur WSGI (gunicorn) derrière Nginx.