0Pricing
Django Academy · Lektion

URL-Muster mit path()

Verknüpfen Sie eine URL in urls.py mit einer View.

URL-Muster mit path() ist eine kostenlose Django Academy-Lektion auf CoddyKit. Dies ist Lektion 2 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 Django Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Django Academy-Kurs umfasst insgesamt 4 Lektionen.

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

Why URLs Need Mapping

Django needs to know which view handles which address. The URLconf is the map that connects a URL to a view.

The urls.py File

Your URL map lives in urls.py. It holds a list called urlpatterns that Django checks top to bottom for a match.

Importing path

The main tool for routing is the path function. Import it from django.urls at the top of the file.

from django.urls import path

Anatomy of path()

The path function takes a route string and the view to call. You list these inside the urlpatterns list.

path('about/', views.about)

A Complete urlpatterns

Here is a working map. The urlpatterns list ties the about/ route to the about view function.

from django.urls import path
from . import views

urlpatterns = [
    path('about/', views.about),
]

Pass the View, Don't Call It

Write views.about without parentheses. Django calls the view for you when the route matches a request.

The Empty Route

An empty string route, '', matches your site's root. It is how you point the home page at a view.

path('', views.home)

Trailing Slashes Matter

Django routes usually end with a slash, like about/. This is a strong convention, so keep it consistent across routes.

Order Decides the Match

Django reads urlpatterns top to bottom and stops at the first match. Put more specific routes above broader ones.

Importing Your Views

Bring your views into urls.py first. The import line lets you reference each view by name in path calls.

from . import views

What Happens on No Match

If no pattern matches the request, Django returns a 404 error. That is your signal to add or fix a route.

Quick Check

Think about how you reference a view inside path().

Recap: You Mapped a URL

In urls.py you import path, list routes in urlpatterns, and point each one at a view. Order and trailing slashes matter. 🔗

Häufig gestellte Fragen

Ist die Lektion „URL-Muster mit path()“ kostenlos?

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

Was lerne ich in „URL-Muster mit path()“?

Verknüpfen Sie eine URL in urls.py mit einer View. Du übst Django 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 Django Academy zu starten?

Keine Vorkenntnisse erforderlich. Django 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 2 von 4.

Wie lange dauert die Lektion „URL-Muster mit path()“?

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 Django Academy-Lektion Code schreiben und ausführen?

Ja. Jede Django 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. Eine funktionsbasierte View schreiben
  2. URL-Muster mit path()
  3. URL-Parameter erfassen
  4. App-URLs einbinden und Routen benennen
← Zurück zu Django Academy