Django Design Patterns and Best Practices
Industry-standard web development techniques and solutions using Python, 2nd Edition
Arun Ravindran
- 282 páginas
- English
- ePUB (apto para móviles)
- Disponible en iOS y Android
Django Design Patterns and Best Practices
Industry-standard web development techniques and solutions using Python, 2nd Edition
Arun Ravindran
Información del libro
Build maintainable websites with elegant Django design patterns and modern best practicesAbout This Book• 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 ChannelsWho This Book Is ForThis 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 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 projectsIn DetailBuilding 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.Style and approachThis comprehensive project-driven guide will enhance your skill set by taking you through the well-known design patterns and industry-standard best practices in Django web development.
Preguntas frecuentes
Información
Models
- The importance of models
- Class diagrams
- Model structural patterns
- Model behavioral patterns
- Migrations
M is bigger than V and C
- The familiar web request-response flow
- Django interactive shell
- Management commands
- Test scripts
- Asynchronous task queues such as Celery
Author's Note: The progress of the SuperBook project will appear in a box like this. You may skip the box, but you will miss the insights, experiences, and drama of working in a web application project.
Steve's first week with his client, the SuperHero Intelligence and Monitoring (SHIM) for short, was a mixed bag. The office was incredibly futuristic, but getting anything done needed a hundred approvals and sign-offs.
Being the lead Django developer, Steve had finished setting up a mid-sized development server hosting four virtual machines over two days. The next morning, the machine itself had disappeared. A washing machine-sized robot nearby said that it had been taken to the forensic department due to unapproved software installations.
The CTO, Hart, was, however, of great help. He asked the machine to be returned in an hour with all the installations intact. He had also sent pre-approvals for the SuperBook project to avoid any such roadblocks in the future.
Later that afternoon, Steve was having a brown-bag lunch with him. Dressed in a beige blazer and light blue jeans, Hart arrived well in time. Despite being taller than most people and having a clean-shaven head, he seemed cool and approachable. He asked if Steve had checked out the previous attempt to build a superhero database in the sixties.
"Oh yes, the Sentinel project, right?" said Steve. "I did. The database seemed to be designed as an Entity-Attribute-Value model, something that I consider an anti-pattern. Perhaps they had very little idea about the attributes of a superhero those days."
Hart almost winced at the last statement. In a slightly lowered voice, he said, "you are right, I didn't. Besides, they gave me only two days to design the whole thing. I believe there was literally a nuclear bomb ticking somewhere."
Steve's mouth was wide open and his sandwich had frozen at its entrance. Hart smiled. "Certainly not my best work. Once it crossed about a billion entries, it took us days to run any kind of analysis on that damn database. SuperBook would zip through that in mere seconds, right?"
Steve nodded weakly. He had never imagined that there would be around a billion superheroes in the first place.
The model hunt
- Nouns in your write-up typically end up as entities.
- Boxes represent entities, which become models.
- Connector lines are bi-directional and represent one of the three types of relationships in Django: one-to-one, one-to-many (implemented with Foreign Keys), and many-to-many.
- The field denoting the one-to-many relationship is defined in the model on the Entity-relationship model (ER-model). In other words, the n ...