Code that is used in many views can be moved into middleware, allowing it to operate either before or after your view code is executed.
- [Voiceover] Let's start section two.…In this section, we're going to cover middleware.…We'll talk about how it works,…what hooks are called,…and when they're called.…How to create custom middleware,…and how to use middleware to catch unhandled exceptions.…In this video, we'll focus on how middleware works…and the various hooks we can target with our middleware.…As we can see in the Django documentation,…middleware is code that hooks into…the request-response cycle of a page view.…Think of it like a plugin for your Django app.…There are quite a few built-in Django plugins.…For example, sessions, CSRF protection, and authentication.…
Pretty much every app will use…at least one piece of middleware:…the built-in common middleware.…If you've ever observed how Django automatically adds…a slash to urls, you can thank common middleware.…If you have some code that runs on multiple pages…of your site, consider if middleware is a good choice…to help you not repeat yourself.…You can see here that a typical Django app…will have several middleware handlers defined.…
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