万本电子书0元读

万本电子书0元读

顶部广告

Django Design Patterns and Best Practices电子书

售       价:¥

14人正在读 | 0人评论 9.8

作       者:Arun Ravindran

出  版  社:Packt Publishing

出版时间:2018-05-31

字       数:36.2万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
Build maintainable websites with elegant Django design patterns and modern best practices About 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 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 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 In Detail 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. Style and approach This 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.
目录展开

Title Page

Copyright and Credits

Django Design Patterns and Best Practices Second Edition

PacktPub.com

Why subscribe?

PacktPub.com

Contributors

About the author

About the reviewer

Packt is searching for authors like you

Preface

Who this book is for

What this book covers

To get the most out of this book

Download the example code files

Download the color images

Conventions used

Get in touch

Reviews

Django and Patterns

Why Django?

The story of Django

A framework is born

Removing the magic

Django keeps getting better

How does Django work?

What is a pattern?

Gang of four patterns

Is Django MVC?

Fowler's patterns

Are there more patterns?

Patterns in this book

Criticism of patterns

How to use patterns

Python Zen and Django's design philosophy

Summary

Application Design

How to gather requirements?

Are you a storyteller?

HTML mockups

Designing the application

Dividing a project into apps

Reuse or roll-your-own?

My app sandbox

Which packages made it?

Best practices before starting a project

SuperBook – your mission, should you choose to accept it

Why Python 3?

Which Django Version to use

Starting the project

Summary

Models

M is bigger than V and C

The model hunt

Splitting models.py into multiple files

Structural patterns

Patterns — normalized models

Problem details

Solution details

Three steps of normalization

First normal form (1NF)

Second normal form (2NF)

Third normal form (3NF)

Django models

Performance and denormalization

Should we always normalize?

Pattern — model mixins

Problem details

Solution details

Model mixins

Pattern — user profiles

Problem details

Solution details

Signals

Admin

Multiple profile types

Pattern – service objects

Problem details

Solution details

Retrieval patterns

Pattern — property field

Problem details

Solution details

Cached properties

Pattern — custom model managers

Problem details

Solution details

Set operations on QuerySets

Chaining multiple QuerySets

Migrations

Summary

Views and URLs

A view from the top

Views got classier

Class-based generic views

Class-Based Views are not always Class-Based Generic Views

View mixins

Order of mixins

Decorators

View patterns

Pattern — access controlled views

Problem details

Solution details

Pattern — context enhancers

Problem details

Solution details

Pattern – services

Problem details

Solution details

Designing URLs

URL anatomy

What happens in urls.py?

Simplified URL pattern syntax

Regular expression URL pattern syntax

Can the simplified syntax replace regular expressions?

Names and namespaces

Pattern order

URL pattern styles

Department store URLs

RESTful URLs

React.js, Vue.js, and other view replacements

Summary

Templates

Understanding Django's template language features

Variables

Attributes

Filters

Tags

Philosophy – don't invent a programming language

Jinja2

Organizing templates

How templates work

Using Bootstrap

But they all look the same!

Lightweight alternatives

Template patterns

Pattern — template inheritance tree

Problem details

Solution details

Pattern — the active link

Problem details

Solution details

A template-only solution

Custom tags

Summary

Admin Interface

Using the admin interface

Enhancing models for the admin

Not everyone should be an admin

Admin interface customizations

Changing the heading

Changing the base and stylesheets

Adding a rich-text editor for WYSIWYG editing

Bootstrap-themed admin

Complete overhauls

Protecting the admin

Pattern – feature flags

Problem details

Solution details

Summary

Forms

How forms work

Forms in Django

Why does data need cleaning?

Displaying forms

Time to be crisp

Understanding CSRF

Form processing with class-based views

Form patterns

Pattern – dynamic form generation

Problem details

Solution details

Pattern – user-based forms

Problem details

Solution details

Pattern – multiple form actions per view

Problem details

Solution details

Separate views for separate actions

Same view for separate actions

Pattern – CRUD views

Problem details

Solution details

Summary

Working Asynchronously

Why asynchronous?

Pitfalls of asynchronous code

Asynchronous patterns

Endpoint callback pattern

Publish-subscribe pattern

Polling pattern

Asynchronous solutions for Django

Working with Celery

How Celery works

Celery best practices

Handling failure

Idempotent tasks

Avoid writing to shared or global state

Database updates without race conditions

Avoid passing complex objects to tasks

Understanding asyncio

asyncio versus threads

The classic web-scraper example

Synchronous web-scraping

Asynchronous web-scraping

Concurrency is not parallelism

Entering Channels

Listening to notifications with WebSockets

Differences from Celery

Summary

Creating APIs

RESTful API

API design

Versioning

Django Rest framework

Improving the Public Posts API

Hiding the IDs

API patterns

Pattern – human browsable interface

Problem details

Solution details

Pattern – Infinite Scrolling

Problem details

Solution details

Summary

Dealing with Legacy Code

Finding the Django Version

Activating the virtual environment

Where are the files? This is not PHP

Starting with urls.py

Jumping around the code

Understanding the code base

Creating the big picture

PyGraphviz installation and usage

Incremental change or a full rewrite?

Writing tests before making any changes

Step-by-step process to writing tests

Legacy database integration

Future proofing

Summary

Testing and Debugging

Why write tests?

TDD

Writing a test case

The assert method

Writing better test cases

Mocking

Pattern – Test fixtures and factories

Problem details

Solution details

Learning more about testing

Debugging

Django debug page

A better debug page

The print function

Logging

The Django Debug Toolbar

The Python debugger pdb

Other debuggers

Debugging Django templates

Summary

Security

Cross-site scripting

Why are your cookies valuable?

How Django helps

Where Django might not help

Cross-site request forgery

How Django helps

Where Django might not help

SQL injection

How Django helps

Where Django might not help

Clickjacking

How Django helps

Shell injection

How Django helps

And the web attacks are unending

A handy security checklist

Summary

Production-Ready

The production environment

Choosing a web stack

Components of a stack

Virtual machines or Docker

Microservices

Hosting

Platform as a service

Virtual private servers

Serverless

Other hosting approaches

Deployment tools

Fabric

Typical deployment steps

Configuration management

Monitoring

Improving Performance

Frontend performance

Backend performance

Templates

Database

Caching

Cached session backend

Caching frameworks

Caching patterns

Summary

Python 2 Versus Python 3

Python 3

Python 3 for Djangonauts

Change all __unicode__ methods into __str__

All classes inherit from object

Calling super() is easier

Relative imports must be explicit

HttpRequest and HttpResponse have str and bytes types

f-strings or formatted string literals

Exception syntax changes and improvements

Standard library reorganized

New goodies

Pyvenv and pip are built in

Other changes

Further information

Other Books You May Enjoy

Leave a review - let other readers know what you think

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部