The built–in, generic class-based views are actually made up of many reusable mixins. Take a look at how you can use the same technique to add your own behaviors into your class-based views.
- [Instructor] A common scenario is that you have…multiple views that work in a similar way.…One of the goals with class-based views…is to reduce code duplication.…You know, the dry principal.…In this video, we'll discuss how mixins can help with that.…Most of the built-in generic class-based views…are made by combining several mixins.…For example, the built-in detail view…uses the single object mixin, the template response mixin,…and the single object template response mixin.…
We can follow their example and create a mixin…that provides key functionality that we'll use…on several of our class-based views.…It turns out that creating your own mixins isn't hard.…This lets you write a mixin once and use it…in several different views, so let's do that.…Here in my editor, in my application,…I created a file called mixins.py.…Here I created a class that extends object,…that's all it does, and it defines a method.…In this case, dispatch.…Dispatch must be defined in the class…I'm going to include this mixin in.…
I'm going to call the superclass versions,…
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