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
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
-
-
-
-
-
-
Creating a dynamic template5m 19s
-
(Locked)
Creating your first Django dynamic webpage5m 32s
-
(Locked)
How can Django can list data with just some small changes4m 58s
-
(Locked)
Introduction to Django class-based views: A few classes have the power to change the world3m 56s
-
(Locked)
</> Code challenge: Showing just popular notes1m 35s
-
(Locked)
Solution: Showing just popular notes2m 36s
-
-
-
-
-
-
-