Mastering Flask Web Development - Second Edition

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Author(s): Daniel Gaspar, Jack Stouffer
Edition: Second Edition
Publisher: Packt
Year: 2018

Language: English
Pages: 327

Cover......Page 1
Title Page......Page 2
Copyright and Credits......Page 3
Packt Upsell......Page 5
Contributors......Page 6
Table of Contents......Page 8
Preface......Page 14
Chapter 1: Getting Started......Page 19
Git basics......Page 20
Git branches and flow......Page 24
Installing the Python package manager on Windows......Page 28
Installing pip Python package manager on macOS X and Linux......Page 29
Pip basics......Page 30
Dependency sandboxing with virtualenv......Page 31
Setting up Docker......Page 32
The beginning of our project......Page 33
Simple application......Page 34
Using Flask's command-line interface......Page 35
Summary......Page 36
Chapter 2: Creating Models with SQLAlchemy......Page 37
Python packages......Page 38
Our first model......Page 39
Creating the user table......Page 42
Reading models......Page 43
Filtering queries......Page 45
Relationships between models......Page 47
One-to-many relationship......Page 48
Many-to-many relationship......Page 51
Constraints and indexing......Page 53
The convenience of SQLAlchemy sessions......Page 55
Database migrations with Alembic......Page 56
Summary......Page 59
Jinja's syntax......Page 60
Filters......Page 61
The int filter......Page 62
The round filter......Page 63
The tojson filter......Page 64
Custom filters......Page 65
Loops......Page 66
Flask-specific variables and functions......Page 68
The url_for() function......Page 69
The get_flashed_messages() function......Page 70
The view function......Page 71
Writing the templates and inheritance......Page 73
The base template......Page 74
The child templates......Page 77
Writing the other templates......Page 80
Flask WTForms......Page 81
WTForms basics......Page 82
Custom validations......Page 83
Posting comments......Page 84
Summary......Page 87
Sessions and globals......Page 88
Request setup and teardown......Page 89
Error pages......Page 90
Class-based views......Page 91
Blueprints......Page 94
Summary......Page 97
Modular application......Page 98
Refactoring the code......Page 100
Application factories......Page 102
Summary......Page 104
Chapter 6: Securing Your App......Page 105
Basic authentication......Page 106
Remote-user authentication......Page 107
LDAP authentication......Page 108
OpenID and OAuth......Page 110
Flask-Login overview......Page 113
Setting up......Page 114
Updating the models......Page 116
Creating the forms......Page 119
Protecting your form from spam......Page 120
Creating views......Page 122
OpenID......Page 127
OAuth......Page 130
Role-based access control (RBAC)......Page 132
Summary......Page 135
Chapter 7: Using NoSQL with Flask......Page 136
Key-value stores......Page 137
Column family stores......Page 138
Graph databases......Page 141
The strengths of RDBMS databases......Page 142
Speed and scale......Page 143
The strengths of NoSQL databases......Page 144
CAP theorem......Page 145
What database to use and when......Page 148
Installing MongoDB......Page 149
Setting up MongoEngine......Page 150
Defining documents......Page 151
Field types......Page 152
The meta attribute......Page 154
Create......Page 156
Read......Page 157
Filtering......Page 159
Update......Page 160
Relationships in NoSQL......Page 161
One-to-many relationships......Page 162
Many-to-many relationships......Page 163
Leveraging the power of NoSQL......Page 164
Summary......Page 169
What is REST?......Page 170
HTTP......Page 171
REST definition and best practices......Page 173
Setting up a RESTful Flask API......Page 177
JWT authentication......Page 180
Output formatting......Page 183
Request arguments......Page 186
Post requests......Page 189
Put requests......Page 191
Summary......Page 193
Chapter 9: Creating Asynchronous Tasks with Celery......Page 194
What is Celery?......Page 195
Setting up Celery and RabbitMQ......Page 196
Creating tasks in Celery......Page 198
Running Celery tasks......Page 202
Celery workflows......Page 203
Callbacks......Page 204
Chain......Page 205
Running tasks periodically......Page 206
Monitoring Celery......Page 208
Web-based monitoring with Flower......Page 209
Creating a reminder app......Page 211
Creating a weekly digest......Page 212
Summary......Page 215
Flask CLI......Page 216
Flask Debug Toolbar......Page 219
Flask Caching......Page 221
Caching views and functions......Page 222
Caching functions with parameters......Page 223
Caching routes with query strings......Page 224
Using Redis as a cache backend......Page 225
Using memcached as a cache backend......Page 226
Flask Assets......Page 227
Flask Admin......Page 229
Creating basic admin pages......Page 231
Creating database admin pages......Page 233
Enhancing administration for the post page......Page 234
Securing Flask Admin......Page 237
Flask-Babel......Page 238
Flask Mail......Page 242
Summary......Page 243
Creating a YouTube Flask extension......Page 244
Creating a Python package......Page 247
Creating blog posts with videos......Page 249
Modifying the response with Flask extensions......Page 251
Summary......Page 253
What are unit tests?......Page 254
How does testing work?......Page 255
Testing the route functions......Page 256
Testing security......Page 260
Testing the REST APIĀ ......Page 262
User interface testing......Page 263
Test coverage......Page 269
Test-driven development......Page 271
Summary......Page 273
Web servers and gateway interfaces......Page 274
Gevent......Page 275
Tornado......Page 276
Nginx and uWSGI......Page 277
Apache and uWSGI......Page 279
Deploying on Heroku......Page 280
Using Celery on Heroku......Page 282
Using Flask on Amazon Elastic Beanstalk......Page 284
Using Amazon RDS......Page 287
Using Celery with Amazon SQS......Page 288
Using Docker......Page 290
Creating Docker images......Page 291
Docker Compose......Page 294
CloudFormation Basics......Page 297
Create and update a CloudFormation stack......Page 305
Building and deploying reliably......Page 307
Creating highly available applications that scale......Page 314
Monitoring and collecting logs......Page 316
Summary......Page 317
Other Books You May Enjoy......Page 318
Index......Page 321