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.
- [Voiceover] On many web apps there are a few views…that are closely related and work on the same set of data.…It makes a lot of sense to group this code together,…into a single class to avoid duplication.…There's that Drive principle again.…Your project may benefit from using…a switchboard style class.…This is a single class, that has the methods…to deal with all of the functionality…related to a certain data set.…The key concept with this class is that it uses…the often misunderstood getattr function…of Python, to call the proper method on the class.…In this example, we're creating a simple…restful API, it's going to use a class-based view…called process payment, and it inherits…from the view base class.…
It's a lot like the one we just demonstrated.…We have a get_amount function, that returns a Json response.…We have a get_tax method, that also returns a Json response,…and the response contains a few keys…that are related to taxes.…We have a get_discount method, again returning…a Json response, with data related to the discount.…
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