没有合适的资源?快使用搜索试试~ 我知道了~
django 1.5 新书
5星 · 超过95%的资源 需积分: 9 610 下载量 162 浏览量
2013-04-23
13:46:57
上传
评论 3
收藏 4.47MB PDF 举报
温馨提示
试读
230页
two-scoops-django-best-practices-1.5 django 1.5 新书
资源推荐
资源详情
资源评论
Two Scoops of Django
Best Practices for Django 1.5
Daniel Greenfeld
Audrey Roy
Two Scoops of Django: Best Practices for Django 1.5
First Edition, Alpha Version, 20120117
by Daniel Greenfeld and Audrey Roy
Copyright © 2013 Daniel Greenfeld, Audrey Roy, and Cartwheel Web.
All rights reserved. is book may not be reproduced in any form, in whole or in part, without written
permission from the authors, except in the case of brief quotations embodied in articles or reviews.
Limit of Liability and Disclaimer of Warranty: e authors have used their best efforts in preparing this
book, and the information provided herein "as is." e information provided is sold without warranty, either
express or implied. Neither the authors nor Cartwheel Web will be held liable for any damages to be caused
either directly or indirectly by the contents of this book.
Trademarks: Rather than indicating every occurence of a trademarked name as such, this book uses the names
only in an editorial fashion and to the benet of the trademark owner with no intention of infringement of
the trademark.
ii
Table of Contents
Authors' Notes xiii
A Few Words From Daniel Greenfeld xiii
A Few Words From Audrey Roy xiv
Introduction xvii
A Word About Our Recommendations xvii
Why Two Scoops of Django? xviii
Before You Begin xix
is book is intended for Django 1.5 and Python 2.7.x xix
Each Chapter Stands On Its Own xix
Conventions Used in is Book xx
Core Concepts xxi
Keep It Simple, Stupid xxi
Fat Models, Helper Functions, in Views, Stupid Templates xxi
Start With Django by Default xxii
Stand on the Shoulders of Giants xxii
1. Coding Style 1
e Importance of Making Your Code Readable 1
PEP 8 2
e Word on Imports 2
Use Relative Imports 3
Avoid Using Import * 5
Django Coding Style Guidelines 6
Follow the Official Django Coding Style Standards 6
Other Good Conventions 6
Never Code to the IDE (or Text Editor) 7
Summary 7
iii
2. The Optimal Django Environment Setup 9
Use the Same Database Locally and in Production 9
Fixtures Are Not a Magic Solution 9
You Can't Examine an Exact Copy of Production Data Locally 10
Different Databases Have Different Field Types and Constraints 10
Use Pip and Virtualenv 11
Install Django and Other Dependencies Via Pip 12
Use a Version Control System 12
Summary 13
3. How To Lay Out Django Projects 15
Django 1.5's Default Project Layout 15
Our Preferred Project Layout 16
Top Level: Repository Root 16
Second Level: Django Project Root 16
ird Level: Conguration Root 17
Sample Project Layout 17
What About the Virtualenv? 20
Using a startproject Template To Generate Our Layout 21
Other Alternatives 21
Summary 21
4. Fundamentals of Django App Design 23
e Golden Rule of Django App Design 23
A Practical Example of Apps in a Project 24
What To Name Your Django Apps 25
When In Doubt, Keep Apps Small 26
Summary 26
5. Settings and Requirements Files 27
Avoid Non-Versioned Local Settings 27
Using Multiple Settings Files 29
Notice How We Use django-admin.py Here 31
A Development Settings Example 31
iv
Multiple Development Settings 33
Keep Secret Keys Out With Environment Variables 34
A Caution Before Using Environment Variables for Secrets 34
How To Set Environment Variables Locally 35
How To Set Environment Variables in Production 35
Handling Missing Secret Key Exceptions 36
Using Multiple Requirements Files 38
Installing From Multiple Requirements Files 39
Using multiple requirements les with Platforms as a Service (PaaS) 40
Handling File Paths in Settings 40
Summary 43
6. Database/Model Best Practices 45
Basics 46
Break Up Apps With Too Many Models 46
Don't Drop Down to Raw SQL Until It's Necessary 46
Add Indexes As Needed 47
Be Careful With Model Inheritance 47
Model Inheritance in Practice: e TimeStampedModel 49
Use South for Migrations 52
Django Model Design 52
Start Normalized 53
Cache Before Denormalizing 53
Denormalize Only If Absolutely Needed 53
When To Use Null and Blank 54
Model Managers 55
Summary 57
7. Function- and Class-Based Views 59
When to use FBVs or CBVs 59
Keep View Logic Out of URLConfs 60
Stick To Loose Coupling in URLConfs 62
What if we aren't using CBVs? 64
Summary 64
8. Best Practices for Class-Based Views 65
v
剩余229页未读,继续阅读
Mchange
- 粉丝: 26
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页