0Pricing
Django Academy · Lektion

ListView und DetailView

Sammlungen und einzelne Datensätze anzeigen

ListView und DetailView ist eine kostenlose Django 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 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.

Two Pages You Always Need

Nearly every app shows a list of things and a page for one thing. Django ships generic views that build both for you. ✨

Meet ListView

ListView fetches many objects and hands them to a template, so you skip writing the query and the render call yourself.

Point ListView at a Model

You give ListView a model, and it runs the query for every row in that table automatically.

from django.views.generic import ListView
from .models import Post

class PostList(ListView):
    model = Post

The Default Template Name

ListView looks for a template named app/model_list.html, like post_list.html, unless you override it.

object_list in the Template

Inside the template the rows arrive as object_list, ready for you to loop over and display.

{% for post in object_list %}
  <li>{{ post.title }}</li>
{% endfor %}

Nicer Names with context_object_name

Set context_object_name so your template variable reads naturally, like posts instead of object_list.

class PostList(ListView):
    model = Post
    context_object_name = "posts"

Meet DetailView

DetailView fetches a single object by its key and renders one focused page for it.

How DetailView Finds the Object

DetailView reads a pk or slug from the URL, then runs get() to load exactly that one record.

from django.views.generic import DetailView

class PostDetail(DetailView):
    model = Post

The Detail Template and object

DetailView renders app/model_detail.html and exposes the record as object in the template.

<h1>{{ object.title }}</h1>
<p>{{ object.body }}</p>

Wiring Them into URLs

Each generic view becomes a URL with as_view(), which turns the class into a callable view.

path("posts/", PostList.as_view()),
path("posts/<int:pk>/", PostDetail.as_view()),

Less Code, Same Result

Together these two views replace dozens of lines of boilerplate, giving you list and detail pages almost for free. 🚀

Quick Check

Where does DetailView get the object it shows?

Recap: List and Detail

You met ListView for collections and DetailView for one record, wired both with as_view(), and skipped tons of boilerplate. 🎉

Häufig gestellte Fragen

Ist die Lektion „ListView und DetailView“ kostenlos?

Ja — der vollständige Text von „ListView und DetailView“ 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 „ListView und DetailView“?

Sammlungen und einzelne Datensätze anzeigen 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 1 von 4.

Wie lange dauert die Lektion „ListView und DetailView“?

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. ListView und DetailView
  2. CreateView und UpdateView
  3. DeleteView und success_url
  4. get_queryset und Templates überschreiben
← Zurück zu Django Academy