Built-in class-based views APILink to this heading

Class-based views API reference. For introductory material, see the Class-based views topic guide.

SpesifikasiLink to this heading

Setiap permintaan dilayani oleh tampilan berbasis-kelas mempunyai keadaan berdiri sendiri; karena itu, itu aman menyimpan variabel keadaan pada instance (yaitu, self.foo = 3 adalah pekerjaan benang-aman).

A class-based view is deployed into a URL pattern using the as_view() classmethod:

Code
urlpatterns = [
    url(r'^view/$', MyView.as_view(size=42)),
]

Arguments passed into as_view() will be assigned onto the instance that is used to service a request. Using the previous example, this means that every request on MyView is able to use self.size. Arguments must correspond to attributes that already exist on the class (return True on a hasattr check).

Base vs Generic viewsLink to this heading

Base class-based views can be thought of as parent views, which can be used by themselves or inherited from. They may not provide all the capabilities required for projects, in which case there are Mixins which extend what base views can do.

Django’s generic views are built off of those base views, and were developed as a shortcut for common usage patterns such as displaying the details of an object. They take certain common idioms and patterns found in view development and abstract them so that you can quickly write common views of data without having to repeat yourself.

Most generic views require the queryset key, which is a QuerySet instance; see Membuat query for more information about QuerySet objects.