You don't have to use generic class-based views. If you plan to override much of the built-in behavior or just don't need it, then you can start out with a simpler class, such as view.
- View Offline
- [Instructor] One of the most common tasks…people do with our web applications is view content.…So let's create a new class-based view…that focuses on that functionality.…Unlike the previous views we've used,…this will not be based on a generic view.…One of the simplest and most commonly-used base classes…is the view class.…A view class typically implements one or more methods…named after the common RESTful verbs,…such as Get or Post.…It makes sense to extract application logic…out of the Get method in order to keep our code…simple and manageable.…In this example, you'll see here…we have our Get method.…
We define the context, and then we call out…to these custom methods to get the total and the tax.…Then our Get view does a typical render…or render to response, whatever's appropriate.…Notice here that we're inheriting from the view class.…This is not a generic view.…This is a very simple view, but it is completely custom…to our application.…You see now how to extend the view class to create…our own custom view.…
Django is one of the world's leading web development platforms. This Python web framework makes your app building experience smoother, faster, and easier. It is a key feature behind the success of many start-ups across the world, including Instagram and Nextdoor. This course introduces next-level advanced concepts to help you build your own professional-grade Django applications.
Author Kevin Veroneau starts off by explaining how class-based views—a powerful, but often poorly understood feature—work in Django. Then learn how to create custom middleware to help organize frequently used code. Have you ever wanted to build a complete RESTful API? Find out how to do just that, starting with a basic read-only API and then adding key-based authentication to allow the full range of CRUD functionality. Plus, discover how to use model managers and the Q method to make it easier to get the data we need to our views and clients.
For the finishing touches, dive into the details of caching to improve application performance, and then add custom management commands to help automate routine tasks.
- Extending class-based views
- Creating custom class-based views
- Managing your database with middleware
- Creating template filters and tags
- Building a RESTful API
- Modeling advanced database relationships and queries
- Using a model manager for your application