Do you have data that is accessed on many views? We already know we can create middleware to reduce duplication, but why not add caching at to middleware to also speed up performance?
- [Narrator] Back in section 2…we looked at creating custom middleware.…We created an example class that would fetch…the user-profile and add it to the request…so that it could be accessed automatically.…In this video, we'll discuss using middleware…to help us with caching.…I'd strongly suggest checking out the Django Debug Toolbar,…which is a tool that helps you see…what is happening inside your app.…It was discussed in detail…as part of my other Django video course…called Learning Django Web Development,…published with PACKT.…You may see that on every page of your website,…a database query is done to fetch the user profile.…
Why do all of this work?…How hard would it be to add caching-support…to our custom middleware?…Well, you just saw on the last video…that caching is not hard.…Here's one way to do it.…The total code is under 20 lines…to get the basic functionality.…You'll see that we're hooking into process_request.…If they're not authenticated, we quickly step out.…Then we try to pull the profile from the cache.…
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