没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
Flask Documentation
Release 0.11-dev
April 10, 2014
CONTENTS
I User’s Guide 1
1 Foreword 3
1.1 What does “micro” mean? . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Configuration and Conventions . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Growing with Flask . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 Foreword for Experienced Programmers 5
2.1 Thread-Locals in Flask . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Develop for the Web with Caution . . . . . . . . . . . . . . . . . . . . . . 5
2.3 The Status of Python 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3 Installation 7
3.1 virtualenv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.2 System-Wide Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.3 Living on the Edge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.4 pip and distribute on Windows . . . . . . . . . . . . . . . . . . . . . . . . 9
4 Quickstart 11
4.1 A Minimal Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.2 Debug Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.3 Routing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.4 Static Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.5 Rendering Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.6 Accessing Request Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.7 Redirects and Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.8 About Responses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.9 Sessions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.10 Message Flashing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.11 Logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.12 Hooking in WSGI Middlewares . . . . . . . . . . . . . . . . . . . . . . . 26
4.13 Deploying to a Web Server . . . . . . . . . . . . . . . . . . . . . . . . . . 26
5 Tutorial 27
5.1 Introducing Flaskr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
5.2 Step 0: Creating The Folders . . . . . . . . . . . . . . . . . . . . . . . . . 28
5.3 Step 1: Database Schema . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
i
5.4 Step 2: Application Setup Code . . . . . . . . . . . . . . . . . . . . . . . . 29
5.5 Step 3: Database Connections . . . . . . . . . . . . . . . . . . . . . . . . . 31
5.6 Step 4: Creating The Database . . . . . . . . . . . . . . . . . . . . . . . . 32
5.7 Step 5: The View Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 34
5.8 Step 6: The Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
5.9 Step 7: Adding Style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
5.10 Bonus: Testing the Application . . . . . . . . . . . . . . . . . . . . . . . . 38
6 Templates 39
6.1 Jinja Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
6.2 Standard Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
6.3 Standard Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
6.4 Controlling Autoescaping . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
6.5 Registering Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
6.6 Context Processors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
7 Testing Flask Applications 43
7.1 The Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
7.2 The Testing Skeleton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
7.3 The First Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
7.4 Logging In and Out . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
7.5 Test Adding Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
7.6 Other Testing Tricks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
7.7 Faking Resources and Context . . . . . . . . . . . . . . . . . . . . . . . . 47
7.8 Keeping the Context Around . . . . . . . . . . . . . . . . . . . . . . . . . 48
7.9 Accessing and Modifying Sessions . . . . . . . . . . . . . . . . . . . . . . 49
8 Logging Application Errors 51
8.1 Error Mails . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
8.2 Logging to a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
8.3 Controlling the Log Format . . . . . . . . . . . . . . . . . . . . . . . . . . 53
8.4 Other Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
9 Debugging Application Errors 57
9.1 When in Doubt, Run Manually . . . . . . . . . . . . . . . . . . . . . . . . 57
9.2 Working with Debuggers . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
10 Configuration Handling 59
10.1 Configuration Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
10.2 Builtin Configuration Values . . . . . . . . . . . . . . . . . . . . . . . . . 60
10.3 Configuring from Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
10.4 Configuration Best Practices . . . . . . . . . . . . . . . . . . . . . . . . . 63
10.5 Development / Production . . . . . . . . . . . . . . . . . . . . . . . . . . 63
10.6 Instance Folders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
11 Signals 67
11.1 Subscribing to Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
11.2 Creating Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
11.3 Sending Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
ii
11.4 Signals and Flask’s Request Context . . . . . . . . . . . . . . . . . . . . . 70
11.5 Decorator Based Signal Subscriptions . . . . . . . . . . . . . . . . . . . . 70
11.6 Core Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
12 Pluggable Views 75
12.1 Basic Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
12.2 Method Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
12.3 Method Based Dispatching . . . . . . . . . . . . . . . . . . . . . . . . . . 77
12.4 Decorating Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
12.5 Method Views for APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
13 The Application Context 81
13.1 Purpose of the Application Context . . . . . . . . . . . . . . . . . . . . . 81
13.2 Creating an Application Context . . . . . . . . . . . . . . . . . . . . . . . 82
13.3 Locality of the Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
13.4 Context Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
14 The Request Context 85
14.1 Diving into Context Locals . . . . . . . . . . . . . . . . . . . . . . . . . . 85
14.2 How the Context Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
14.3 Callbacks and Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
14.4 Teardown Callbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
14.5 Notes On Proxies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
14.6 Context Preservation on Error . . . . . . . . . . . . . . . . . . . . . . . . 88
15 Modular Applications with Blueprints 91
15.1 Why Blueprints? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
15.2 The Concept of Blueprints . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
15.3 My First Blueprint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
15.4 Registering Blueprints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
15.5 Blueprint Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
15.6 Building URLs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
16 Flask Extensions 97
16.1 Finding Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
16.2 Using Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
16.3 Flask Before 0.8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
17 Working with the Shell 99
17.1 Creating a Request Context . . . . . . . . . . . . . . . . . . . . . . . . . . 99
17.2 Firing Before/After Request . . . . . . . . . . . . . . . . . . . . . . . . . 100
17.3 Further Improving the Shell Experience . . . . . . . . . . . . . . . . . . . 100
18 Patterns for Flask 101
18.1 Larger Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
18.2 Application Factories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
18.3 Application Dispatching . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
18.4 Implementing API Exceptions . . . . . . . . . . . . . . . . . . . . . . . . 109
18.5 Using URL Processors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
iii
剩余305页未读,继续阅读
资源评论
jayn9876
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 转载使用许可协议范本(互联网行业)模版.doc
- 软件产业运行情况调研问卷模版.doc
- 软件产品发布管理流程.doc
- 软件仿真多机串行通信.doc
- Python大作业:音乐播放软件(爬虫+可视化+数据分析+数据库)
- 课程设计-python爬虫-爬取日报,爬取日报文章后存储到本地,附带源代码+课程设计报告
- 软件和信息技术服务行业投资与前景预测.pptx
- 课程设计-基于SpringBoot + Mybatis+python爬虫NBA球员数据爬取可视化+源代码+文档+sql+效果图
- 软件品质管理系列二项目策划规范.doc
- 基于TensorFlow+PyQt+GUI的酒店评论情感分析,支持分析本地数据文件和网络爬取数据分析+源代码+文档说明+安装教程
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功