在好例子网,分享、交流、成长!
您当前所在位置:首页Python 开发实例Python语言基础 → Learning Flask Framework.pdf

Learning Flask Framework.pdf

Python语言基础

下载此实例
  • 开发语言:Python
  • 实例大小:2.61M
  • 下载次数:12
  • 浏览次数:133
  • 发布时间:2020-07-21
  • 实例类别:Python语言基础
  • 发 布 人:haoliziKK
  • 文件格式:.pdf
  • 所需积分:2
 相关标签: flask

实例介绍

【实例简介】

【实例截图】

from clipboard

【核心代码】

Table of Contents
Preface vii
Chapter 1: Creating Your First Flask Application 1
What is Flask? 1
With great freedom comes great responsibility 2
Setting up a development environment 2
Supporting Python 3 3
Installing Python packages 3
Installing pip 3
Installing virtualenv 4
Why use virtualenv? 4
Installing virtualenv with pip 4
Creating your first Flask app 5
Installing Flask in your virtualenv 6
Hello, Flask! 6
Understanding the code 7
Routes and requests 9
Reading values from the request 10
Debugging Flask applications 11
Introducing the blog project 14
The spec 15
Creating the blog project 15
A barebones Flask app 17
Zooming out 18
The import flow 19
Summary 20
Chapter 2: Relational Databases with SQLAlchemy 21
Why use a relational database? 22
Introducing SQLAlchemy 23
Installing SQLAlchemy 24
Table of Contents
[ ii ]
Using SQLAlchemy in our Flask app 24
Choosing a database engine 25
Connecting to the database 25
Creating the Entry model 26
Creating the Entry table 29
Working with the Entry model 30
Making changes to an existing entry 32
Deleting an entry 32
Retrieving blog entries 32
Filtering the list of entries 33
Special lookups 34
Combining expressions 35
Negation 36
Operator precedence 37
Building a tagging system 37
Adding and removing tags from entries 41
Using backrefs 42
Making changes to the schema 43
Adding Flask-Migrate to our project 43
Creating the initial migration 44
Adding a status column 45
Summary 46
Chapter 3: Templates and Views 47
Introducing Jinja2 48
Basic template operations 49
Loops, control structures, and template programming 51
Jinja2 built-in filters 55
Creating a base template for the blog 57
Creating a URL scheme 60
Defining the URL routes 62
Building the index view 63
Building the detail view 66
Listing entries matching a given tag 67
Listing all the tags 68
Full-text search 69
Adding pagination links 71
Enhancing the blog app 73
Summary 73
Table of Contents
[ iii ]
Chapter 4: Forms and Validation 75
Getting started with WTForms 75
Defining a form for the Entry model 76
A form with a view 77
The create.html template 78
Handling form submissions 80
Validating input and displaying error messages 82
Editing existing entries 85
The edit.html template 86
Deleting entries 89
Cleaning up 90
Using flash messages 91
Displaying flash messages in the template 93
Saving and modifying tags on posts 94
Image uploads 96
Processing file uploads 97
The image upload template 99
Serving static files 100
Summary 101
Chapter 5: Authenticating Users 103
Creating a user model 104
Installing Flask-Login 105
Implementing the Flask-Login interface 107
Creating user objects 108
Login and logout views 110
The login template 112
Logging out 113
Accessing the current user 114
Restricting access to views 114
Storing an entry's author 115
Setting the author on blog entries 117
Protecting the edit and delete views 117
Displaying a user's drafts 119
Sessions 120
Summary 121
Chapter 6: Building an Administrative Dashboard 123
Installing Flask-Admin 123
Adding Flask-Admin to our app 125
Table of Contents
[ iv ]
Exposing models through the Admin 126
Customizing the list views 129
Adding search and filtering to the list view 132
Customizing Admin model forms 134
Enhancing the User form 136
Generating slugs 138
Managing static assets via the Admin 140
Securing the admin website 141
Creating an authentication and authorization mixin 143
Setting up a custom index page 144
Flask-Admin templates 145
Reading more 146
Summary 146
Chapter 7: AJAX and RESTful APIs 147
Creating a comment model 147
Creating a schema migration 149
Installing Flask-Restless 149
Setting up Flask-Restless 150
Making API requests 151
Creating comments using AJAX 154
AJAX form submissions 156
Validating data in the API 159
Preprocessors and postprocessors 160
Loading comments using AJAX 161
Retrieving the list of comments 163
Reading more 166
Summary 166
Chapter 8: Testing Flask Apps 167
Unit testing 167
Python's unit test module 168
A simple math test 169
Flask and unit testing 171
Testing a page 173
Testing an API 175
Test-friendly configuration 176
Mocking objects 177
Table of Contents
[ v ]
Logging and error reporting 179
Logging 180
Logging to file 180
Custom log messages 181
Levels 181
Error reporting 182
Read more 182
Summary 182
Chapter 9: Excellent Extensions 183
SeaSurf and CSRF protection of forms 183
Creating Atom feeds 185
Syntax highlighting using Pygments 186
Simple editing with Markdown 190
Caching with Flask-Cache and Redis 192
Creating secure, stable versions of your site by creating
static content 194
Commenting on a static site 195
Synchronizing multiple editors 195
Asynchronous tasks with Celery 196
Creating command line instructions with Flask-script 199
References 200
Summary 201
Chapter 10: Deploying Your Application 203
Running Flask with a WSGI server 203
Apache's httpd 204
Serving static files 206
Nginx 207
Serving static files 209
Gunicorn 210
Securing your site with SSL 210
Getting your certificate 211
Apache httpd 212
Nginx 214
Gunicorn 215
Automating deployment using Ansible 216
Read more 219
Summary 219
Index 221

标签: flask

实例下载地址

Learning Flask Framework.pdf

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警