▶Book Description
Building secure and maintainable web applications requires comprehensive knowledge. The second edition of this book not only sheds light on Django, but also encapsulates years of experience in the form of design patterns and best practices. Rather than sticking to GoF design patterns, the book looks at higher-level patterns. Using the latest version of Django and Python, you'll learn about Channels and asyncio while building a solid conceptual background. The book compares design choices to help you make everyday decisions faster in a rapidly changing environment.
You'll first learn about various architectural patterns, many of which are used to build Django. You'll start with building a fun superhero project by gathering the requirements, creating mockups, and setting up the project. Through project-guided examples, you'll explore the Model, View, templates, workflows, and code reusability techniques. In addition to this, you'll learn practical Python coding techniques in Django that'll enable you to tackle problems related to complex topics such as legacy coding, data modeling, and code reusability.
You'll discover API design principles and best practices, and understand the need for asynchronous workflows. During this journey, you'll study popular Python code testing techniques in Django, various web security threats and their countermeasures, and the monitoring and performance of your application.
▶What You Will Learn
⦁ Make use of common design patterns to help you write better code
⦁ Implement best practices and idioms in this rapidly evolving framework
⦁ Deal with legacy code and debugging
⦁ Use asynchronous tools such as Celery, Channels, and asyncio
⦁ Use patterns while designing API interfaces with the Django REST Framework
⦁ Reduce the maintenance burden with well-tested, cleaner code
⦁ Host, deploy, and secure your Django projects
▶Key Features
⦁ Explore aspects of Django from Models and Views to testing and deployment
⦁ Understand the nuances of web development such as browser attack and data design
⦁ Walk through various asynchronous tools such as Celery and Channels
▶Who This Book Is For
This book is for you whether you're new to Django or just want to learn its best practices. You do not have to be an expert in Django or Python. No prior knowledge of patterns is expected for reading this book but it would be helpful.
▶What this book covers
⦁ Chapter 1, Django and Patterns, helps us understand Django better by telling us why it was created and how it has evolved over time. Then, it introduces design patterns, their importance, and several popular pattern collections.
⦁ Chapter 2, Application Design, guides us through the early stages of an application's life cycle, such as gathering requirements and creating mock-ups. We will also see how to break your project into modular apps through our running example—.SuperBook.
⦁ Chapter 3, Models, gives us insights into how models can be graphically represented, structured using several kinds of patterns and can be later altered using migrations.
⦁ Chapter 4, Views and URLs, shows us how function-based views evolved into class-based views with the powerful mixin concept, familiarizes us with useful view patterns, and teaches how short and meaningful URLs are designed.
⦁ Chapter 5, Templates, walks us through Django template language constructs, explaining its design choices, suggests how to organize template files, introduces handy template patterns, and points to several ways Bootstrap can be integrated and customized.
⦁ Chapter 6, Admin Interface, focuses on how to use Django's brilliant out-of-the box admin interface more effectively and several ways to customize it, from enhancing the models to toggling feature flags.
⦁ Chapter 7, Forms, illustrates the often confusing form workflow, different ways of rendering forms, improving a form's appearance using crispy forms, and various applied form patterns.
⦁ Chapter 8, Working Asynchronously, tours various asynchronous solutions for the Django developer, from the feature-rich Celery task queues, Python 3's asyncio, to the brand new Channels, and compares them for you.
⦁ Chapter 9, Creating APIs, explains RESTful API design concepts with practical advice on topics such as versioning, error handling, and design patterns using the Django REST framework.
⦁ Chapter 10, Dealing with Legacy Code, tackles common issues with legacy Django projects, such as identifying the right version, locating the files, where to start reading a large code base, and how to enhance it to add new functionality.
⦁ Chapter 11, Testing and Debugging, gives us an overview of various testing and debugging tools and techniques, introducing test-driven development, mocking, logging, and debuggers.
⦁ Chapter 12, Security, familiarizes you with various web security threats and their counter measures, specifically looking at how Django can protect you. Finally, a handy security checklist reminds you of the commonly overlooked areas.
⦁ Chapter 13, Production-Ready, is a crash course in deploying a public-facing application beginning with choosing your webstack, understanding hosting options, and walking through a typical deployment process. We go into the details of monitoring and performance at this stage.
⦁ Appendix A, Python 2 Versus Python 3, introduces Python 3 to Python 2 developers. Starting off by showing the most relevant differences while working in Django, we move on to the new modules and tools offered in Python 3.