In most cases, we write view functions in views.py. However, we may write many duplicate codes such as post_list = Post.objects.all() and post = get_object_or_404(Post, pk = pk). In order to solve this problem, Django provides us generic view class. There are two common class we can inherite. One is ListView, the other is DetailView.
Class based view
1 2 3 4 5 6 7 8
classPostView(ListView): model = Post template_name = 'blog/index.html' context_object_name = 'post_list'