万本电子书0元读

万本电子书0元读

顶部广告

Django Design Patterns and Best Practices电子书

售       价:¥

9人正在读 | 0人评论 6.2

作       者:Arun Ravindran

出  版  社:Packt Publishing

出版时间:2015-03-31

字       数:200.4万

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

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

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
If you want to learn how best to utilize commonly found patterns and learn best practices in developing applications with Django, this is the book for you. This book, like Django itself, is accessible to amateur and professional developers alike and assumes little in the way of prior experience. Although written for Python 3, the majority of the code in this book works in Python 2 or can be easily translated.
目录展开

Django Design Patterns and Best Practices

Table of Contents

Django Design Patterns and Best Practices

Credits

About the Author

About the Reviewers

www.PacktPub.com

Support files, eBooks, discount offers, and more

Why subscribe?

Free access for Packt account holders

Preface

What this book covers

What you need for this book

Who this book is for

Conventions

Reader feedback

Customer support

Downloading the example code

Errata

Piracy

Questions

1. 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

Best practices

Python Zen and Django's design philosophy

Summary

2. Application Design

How to gather requirements

Are you a story teller?

HTML mockups

Designing the application

Dividing a project into Apps

Reuse or roll-your-own?

My app sandbox

Which packages made it?

Before starting the project

SuperBook – your mission, should you choose to accept it

Why Python 3?

Starting the project

Summary

3. 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 or 2NF

Third normal form or 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

4. Views and URLs

A view from the top

Views got classier

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?

The URL pattern syntax

Mnemonic – parents question pink action-figures

Names and namespaces

Pattern order

URL pattern styles

Departmental store URLs

RESTful URLs

Summary

5. Templates

Understanding Django's template language features

Variables

Attributes

Filters

Tags

Philosophy – don't invent a programming language

Organizing templates

Support for other template languages

Using Bootstrap

But they all look the same!

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

6. 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

7. 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

8. 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

Incremental change or a full rewrite?

Write tests before making any changes

Step-by-step process to writing tests

Legacy databases

Summary

9. Testing and Debugging

Why write tests?

Test-driven development

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

10. Security

Cross-site scripting (XSS)

Why are your cookies valuable?

How Django helps

Where Django might not help

Cross-Site Request Forgery (CSRF)

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 list goes on

A handy security checklist

Summary

11. Production-ready

Production environment

Choosing a web stack

Components of a stack

Hosting

Platform as a service

Virtual private servers

Other hosting approaches

Deployment tools

Fabric

Typical deployment steps

Configuration management

Monitoring

Performance

Frontend performance

Backend performance

Templates

Database

Caching

Cached session backend

Caching frameworks

Caching patterns

Summary

A. Python 2 versus Python 3

But I still use Python 2.7!

Python 3

Python 3 for Djangonauts

Change all the __unicode__ methods into __str__

All classes inherit from the object class

Calling super() is easier

Relative imports must be explicit

HttpRequest and HttpResponse have str and bytes types

Exception syntax changes and improvements

Standard library reorganized

New goodies

Using Pyvenv and Pip

Other changes

Further information

Index

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

发表评论

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

买过这本书的人还买过

读了这本书的人还在读

回顶部