0Pricing
Flask Academy · Lektion

Der Decorator @app.route

Verknüpfen Sie einen URL-Pfad mit einer View-Funktion.

Der Decorator @app.route ist eine kostenlose Flask Academy-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Flask Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Flask Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

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. 🎉

Häufig gestellte Fragen

Ist die Lektion „Der Decorator @app.route“ kostenlos?

Ja — der vollständige Text von „Der Decorator @app.route“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Flask Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Flask Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Der Decorator @app.route“?

Verknüpfen Sie einen URL-Pfad mit einer View-Funktion. Du übst Flask Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Flask Academy zu starten?

Keine Vorkenntnisse erforderlich. Flask Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.

Wie lange dauert die Lektion „Der Decorator @app.route“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Flask Academy-Lektion Code schreiben und ausführen?

Ja. Jede Flask Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Der Decorator @app.route
  2. Wie aus einer Anfrage eine Antwort wird
  3. Strings, HTML und Statuscodes zurückgeben
  4. Mehrere Routen in einer App
← Zurück zu Flask Academy