0Pricing
Flask Academy · Lezione

Il decoratore @app.route

Colleghi un percorso URL a una view function.

Il decoratore @app.route è una lezione Flask Academy gratuita su CoddyKit. Questa è la lezione 1 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Flask Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Flask Academy include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

What a Route Is

A route connects a URL path to a Python function. When someone visits that path, Flask runs your function and sends back whatever it returns.

Meet the Decorator

You attach a route using @app.route, a decorator written on the line just above your function. It tells Flask which path this function should handle.

@app.route("/")
def home():
    return "Welcome!"

View Functions

The function below a route is called a view function. Its job is simple: build a response for one specific URL and return it.

The Path Argument

The string you pass, like "/about", is the URL path. It always starts with a slash and tells Flask exactly where this page lives.

@app.route("/about")
def about():
    return "About us"

The Root Path

A single slash, "/", is the root path. It is your home page, the page people see when they open your site with no extra path.

Returning a Response

Whatever your view function returns becomes the page body. A plain string is the simplest response Flask can send to a browser.

@app.route("/hi")
def hi():
    return "Hi there"

Why a Decorator?

The @ symbol means decorator. It registers your function with Flask without you calling anything by hand, so Flask knows about the route at startup.

Function Names Are Yours

The function name does not have to match the URL. Pick clear names like contact or profile, since Flask uses them later to build links.

One Decorator, One Path

Each @app.route binds one path to one function. Want another page? Write another decorator and another function below it.

@app.route("/contact")
def contact():
    return "Email us"

Order Inside the File

You can declare routes in any order in your file. Flask matches by the requested path, not by which function you wrote first.

Paths Are Case Sensitive

Route paths are case sensitive after the host. "/About" and "/about" are different URLs, so keep your paths lowercase and consistent.

Quick Check

Let us make sure the decorator clicked.

Recap

You now wire pages with @app.route: a path string, a view function, and a returned response. That trio is the heart of every Flask app. 🎉

Domande Frequenti

La lezione «Il decoratore @app.route» è gratuita?

Sì — il testo completo di «Il decoratore @app.route» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Flask Academy, passa a CoddyKit PRO. Il corso Flask Academy include 4 lezioni in totale.

Cosa imparerò in «Il decoratore @app.route»?

Colleghi un percorso URL a una view function. Eserciti Flask Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Flask Academy?

Non è richiesta alcuna esperienza precedente. Flask Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 1 di 4.

Quanto tempo richiede la lezione «Il decoratore @app.route»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Flask Academy?

Sì. Ogni lezione Flask Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Il decoratore @app.route
  2. Come una richiesta diventa una risposta
  3. Restituire stringhe, HTML e codici di stato
  4. Più route in una sola app
← Torna a Flask Academy