From the course: Django Essential Training

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Introduction to Django class-based views: A few classes have the power to change the world

Introduction to Django class-based views: A few classes have the power to change the world

From the course: Django Essential Training

Introduction to Django class-based views: A few classes have the power to change the world

- [Instructor] We worked with templates, but now it's time for more complex views. Let's start with our last endpoint. On the notes, let's go to views.py file. And in here, let's import from Django.views.generic import ListView. Okay, now we can start our class-based view. Let's go to create a class. So let's call it NotesListView that inherits from ListView. And we need to add here which model we're listing objects from. So let's add here Model = Notes. Okay. And because our template is expecting to receive a list called Notes, we should also add here that the context object name is different from the default. The default is objects, but we call it notes. That's it, that's our whole endpoint. The only thing we need to do now is change the endpoint URL. So let's go back here, then change list to NotesListView.as view, and that's it. We can go back here and also delete our old endpoint. We don't need it anymore. Okay, it restarted, so let's try it out. Instead of homes, we're going to…

Contents