基本信息
源码名称:Learning Flask Framework.pdf
源码大小:2.61M
文件格式:.pdf
开发语言:Python
更新时间:2020-07-21
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍

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