Mastering Django Web Development shows you how to use advanced concepts to help you build professional grade Django applications.
We start off by learning how class-based views work so that you can fully benefit from this powerful, but often poorly understood feature. We’ll then create custom middleware which will help us better organize frequently used code.
Have you ever wanted to build a complete REST API? We’ll do just that, starting out with a basic read-only API and then adding key-based authentication to allow the full range of CRUD functionality. We’ll also utilize model managers and the Q method so that we can make it easier to get the data we need to our views and clients.
For the finishing touches, we’ll dive into the details of caching, to improve our application performance, and then add custom management commands to help us automate routine tasks.
By the end of this video course, you will emerge a Django expert.
About The Authors
Kevin Veroneau is a very active Python and Django developer who has worked for many start-ups, has an active Python blog, and has worked on a magnitude of Python projects over the years.
Matthew Nuzum has been developing web applications since 1999 and has worked for several start-ups including Canonical, the makers of Ubuntu, as well as Fortune 500 companies. He has a passion for helping others learn new technologies and has written numerous tutorials and help documents as well as running a web-focused user group based in his hometown of Des Moines.
Generic class-based views provide a lot of functionality. Let's take a look at how you can easily extend them to create your own custom solutions.
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.
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.
You can create a single class-based view that can handle all of the operations for a set of data. These are sometimes called switchboard classes, and they can help make your code easier to maintain.
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.
Middleware classes are not fancy; they simply have one or more methods that correspond to one of the five predefined hooks available. Let's take a closer look at them here.
Showing users exceptions is unprofessional and may be a security problem. Let's examine an easier way to create middleware that catches and responds to unhandled exceptions
In this video we will explore the possibility of creating custom filters to make frequently used behaviors easily reusable for everyone on our team.
If you need a functionality that is too sophisticated for a filter, it should be a template tag. These are of several kinds, such as simple_tag for basic functionality and a template inclusion tag to bring in entire templates.
With the growing popularity of Angular.js and similar tools, more applications need to provide a RESTful API. Tastypie is a Python module that does most of the work for us. Let's check it out.
Sometimes you want to modify the data before it goes out to the API. Tastypie makes it easy to add or customize the data returned from the API.
Not all applications work with a read-only API. Sometimes, you want full CRUD support from your API. You need to add an authentication step before you make this functionality available. Fortunately, Tastypie does all of this for us.
Sometimes, you want to combine data from different models. It's not hard to do this with Python, but generic relationships allow Django to do this for you.
Have you wished you could add or edit many records to the database at once? With only a few lines of code, you can add this capability to your application.
Django's ORM works fine when your filters are combined using the AND operator. If you want to perform more complicated queries, you should use the Q function, which just gives you more flexibility with your logic.
Is your application running slow? You may be performing expensive operations more often than necessary. We can use low-level caching operations to have tight control over our application's performance.
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?
If your cache needs are simpler, you can perform caching at the template level. This can provide a tremendous improvement in performance and is easy to use.
Do you frequently perform the same query and filter operation in multiple views? Avoid duplication using model managers.
You may have a similar logic in multiple areas of the site to deal with inserting data. You can create a manager function that accepts your data as a parameter and centralizes your insertion logic.
Do you perform regular maintenance on your application? You can simplify periodic cron tasks by creating custom manage.py commands.
Packt has been committed to developer learning since 2004. A lot has changed in software since then - but Packt has remained responsive to these changes, continuing to look forward at the trends and tools defining the way we work and live. And how to put them to work.
With an extensive library of content - more than 4000 books and video courses -Packt's mission is to help developers stay relevant in a rapidly changing world. From new web frameworks and programming languages, to cutting edge data analytics, and DevOps, Packt takes software professionals in every field to what's important to them now.
From skills that will help you to develop and future proof your career to immediate solutions to every day tech challenges, Packt is a go-to resource to make you a better, smarter developer.
Packt Udemy courses continue this tradition, bringing you comprehensive yet concise video courses straight from the experts.