没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论



















How to Tango with Django 1.9
A beginners guide to Python/Django
Leif Azzopardi and David Maxwell
This book is for sale at http://leanpub.com/tangowithdjango19
This version was published on 2016-10-04
This is a Leanpub book. Leanpub empowers authors and publishers with the Lean Publishing
process. Lean Publishing is the act of publishing an in-progress ebook using lightweight tools and
many iterations to get reader feedback, pivot until you have the right book and build traction once
you do.
© 2016 Leif Azzopardi and David Maxwell

Tweet This Book!
Please help Leif Azzopardi and David Maxwell by spreading the word about this book on Twitter!
The suggested tweet for this book is:
I’m now ready to Tango with Django @tangowithdjango
The suggested hashtag for this book is #tangowithdjango.
Find out what other people are saying about the book by clicking on this link to search for this
hashtag on Twitter:
https://twitter.com/search?q=#tangowithdjango

CONTENTS
Contents
1. Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Why Work with this Book? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 What you will Learn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Technologies and Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Rango: Initial Design and Specification . . . . . . . . . . . . . . . . . . . . . . . 4
1.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2. Getting Ready to Tango . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.1 Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.2 The Python Package Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.3 Virtual Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.4 Integrated Development Environment . . . . . . . . . . . . . . . . . . . . . . . . 14
2.5 Code Repository . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3. Django Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.1 Testing Your Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.2 Creating Your Django Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.3 Creating a Django Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.4 Creating a View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.5 Mapping URLs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.6 Basic Workflows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4. Templates and Media Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4.1 Using Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4.2 Serving Static Media Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
4.3 Serving Media . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
4.4 Basic Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
5. Models and Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
5.1 Rango’s Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
5.2 Telling Django about Your Database . . . . . . . . . . . . . . . . . . . . . . . . . 45
5.3 Creating Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
5.4 Creating and Migrating the Database . . . . . . . . . . . . . . . . . . . . . . . . 48
5.5 Django Models and the Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
www.tangowithdjango.com

CONTENTS
5.6 Configuring the Admin Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
5.7 Creating a Population Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
5.8 Workflow: Model Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
6. Models, Templates and Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
6.1 Workflow: Data Driven Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
6.2 Showing Categories on Rango’s Homepage . . . . . . . . . . . . . . . . . . . . . 63
6.3 Creating a Details Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
7. Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
7.1 Basic Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
7.2 Page and Category Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
8. Working with Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
8.1 Using Relative URLs in Templates . . . . . . . . . . . . . . . . . . . . . . . . . . 90
8.2 Dealing with Repetition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
8.3 Template Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
8.4 The render() Method and the request Context . . . . . . . . . . . . . . . . . . . 98
8.5 Custom Template Tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
8.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
9. User Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
9.1 Setting up Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
9.2 Password Hashing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
9.3 Password Validators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
9.4 The User Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
9.5 Additional User Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
9.6 Creating a User Registration View and Template . . . . . . . . . . . . . . . . . . 107
9.7 Implementing Login Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . 114
9.8 Restricting Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
9.9 Logging Out . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
9.10 Taking it Further . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
10. Cookies and Sessions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
10.1 Cookies, Cookies Everywhere! . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
10.2 Sessions and the Stateless Protocol . . . . . . . . . . . . . . . . . . . . . . . . . . 125
10.3 Setting up Sessions in Django . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
10.4 A Cookie Tasting Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
10.5 Client Side Cookies: A Site Counter Example . . . . . . . . . . . . . . . . . . . . 128
10.6 Session Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
10.7 Browser-Length and Persistent Sessions . . . . . . . . . . . . . . . . . . . . . . . 133
10.8 Clearing the Sessions Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
10.9 Basic Considerations and Workflow . . . . . . . . . . . . . . . . . . . . . . . . . 134
www.tangowithdjango.com
剩余287页未读,继续阅读
资源评论


小九不懂SAP
- 粉丝: 4532
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 该项目为一个集数据抓取与展示一体的ACM队员数据系统,基于Django、python实现。.zip
- 辅助背单词软件,基于艾宾浩斯记忆曲线(其实背啥都行)的Python重构版,增加在线查词与翻译等功能.zip
- 基于C开发的命令行输入输出流重定向与实时分析工具_支持快捷按键和文本框输入实时过滤计算分析多格式结果呈现文本提示弹窗曲线表格支持批量测试和日志抓取_用于开发调试协议分.zip
- 各种有用的web api 基于Golang, Python(tornado django scrapy gevent).zip
- 华南理工大学找到卷王,基于 Python 的综测系统数据爬虫.zip
- 湖南大学(HNU)数据库系统课程大作业 ATM系统 前端基于Python的PyQt5,后端基于MySQL.zip
- (新闻爬虫),基于python+Flask+Echarts,实现首页与更多新闻页面爬取
- 基于 Flask + Requests 的全平台音乐接口 Python 版.zip
- 基于 FFmpeg ,使用 Python 开发的批量媒体文件格式转换器。.zip
- 基于 CAI 的 OneBot Python 实现.zip
- 基于 nonebot2 开发的消息交互式 Python 解释器,依赖 docker SDK.zip
- 基于 Python 3 + Django 2 开发的用于适配手机的简单 Jenkins 构建平台.zip
- Python 语言的爬楼梯问题实现-计算爬到第 n 级台阶的方法数
- 基于 Napcat, NcatBot, JMComic-Crawler-Python 的 QQ 机器人。.zip
- 基于 Python Tornado 的博客程序 (练习).zip
- 基于 Python 3.5 + Django 2.0 开发的简单个人博客.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
