Flask: Building Python Web Services

Author: Gareth Dwyer;Shalabh Aggarwal;Jack Stouffer  

Publisher: Packt Publishing‎

Publication year: 2017

E-ISBN: 9781787285446

P-ISBN(Paperback): 9781787288225

Subject: TP301.6 algorithm theory;TP31 computer software

Keyword: 计算机软件,算法理论,自动化技术、计算机技术

Language: ENG

Access to resources Favorite

Disclaimer: Any content in publications that violate the sovereignty, the constitution or regulations of the PRC is not accepted or approved by CNPIEC.

Chapter

Chapter 1: Hello, World!

Introducing Flask

Creating our development environment

Writing "Hello, World!"

Deploying our application to production

Summary

Chapter 2: Getting Started with Our Headlines Project

Setting up our project and a Git repository

Creating a new Flask application

Introduction to RSS and RSS feeds

Summary

Chapter 3: Using Templates in Our Headlines Project

Introducing Jinja

Basic use of Jinja templates

Advanced use of Jinja templates

Summary

Chapter 4: User Input for Our Headlines Project

Getting user input using HTTP GET

Getting user input using HTTP POST

Adding weather and currency data

Summary

Chapter 5: Improving the User Experience of Our Headlines Project

Adding cookies to our Headlines application

Adding CSS to our Headlines application

Summary

Chapter 6: Building an Interactive Crime Map

Setting up a new Git repository

Understanding relational databases

Installing and configuring MySQL on our VPS

Creating our Crime Map database in MySQL

Creating a basic database web application

Summary

Chapter 7: Adding Google Maps to Our Crime Map Project

Running a database application locally

Adding an embedded Google Maps widget to our application

Adding an input form for new crimes

Displaying existing crimes on our map

Summary

Chapter 8: Validating User Input in Our Crime Map Project

Choosing where to validate

Trying out an XSS example

Validating and sanitizing

Summary

Chapter 9: Building a Waiter Caller App

Setting up a new Git repository

Using Bootstrap to kick-start our application

Adding user account control to our application

Summary

Chapter 10: Template Inheritance and WTForms in Waiter Caller Project

Adding the Account and Dashboard pages

Shortening URLs using the bitly API

Adding functionality to handle attention requests

Adding user feedback with WTForms

Summary

Chapter 11: Using MongoDB with Our Waiter Caller Project

Introducing MongoDB

Installing MongoDB

Using the MongoDB shell

Introducing PyMongo

Testing our application in production

Adding some finishing touches

Summary

Appendix: A Sneak Peek into the Future

Expanding the projects

Expanding your Flask knowledge

Expanding your web development knowledge

Summary

Module 2

Chapter 1: Flask Configurations

Introduction

Environment setup with virtualenv

Handling basic configurations

Class-based settings

Organization of static files

Being deployment specific with instance folders

Composition of views and models

Creating a modular web app with blueprints

Making a Flask app installable using setuptools

Chapter 2: Templating with Jinja2

Introduction

Bootstrap layout

Block composition and layout inheritance

Creating a custom context processor

Creating a custom Jinja2 filter

Creating a custom macro for forms

Advanced date and time formatting

Chapter 3: Data Modeling in Flask

Introduction

Creating a SQLAlchemy DB instance

Creating a basic product model

Creating a relational category model

Database migration using Alembic and Flask-Migrate

Model data indexing with Redis

Opting the NoSQL way with MongoDB

Chapter 4: Working with Views

Introduction

Writing function-based views and URL routes

Class-based views

URL routing and product-based pagination

Rendering to templates

Dealing with XHR requests

Decorator to handle requests beautifully

Creating custom 404 and 500 handlers

Flashing messages for better user feedback

SQL-based searching

Chapter 5: Webforms with WTForms

Introduction

SQLAlchemy model data as form representation

Validating fields on the server side

Creating a common forms set

Creating custom fields and validation

Creating a custom widget

Uploading files via forms

Cross-site Request Forgery protection

Chapter 6: Authenticating in Flask

Introduction

Simple session-based authentication

Authenticating using the Flask-Login extension

Using OpenID for authentication

Using Facebook for authentication

Using Google for authentication

Using Twitter for authentication

Chapter 7: RESTful API Building

Introduction

Creating a class-based REST interface

Creating an extension-based REST interface

Creating a SQLAlchemy-independent REST API

A complete REST API example

Chapter 8: Admin Interface for Flask Apps

Introduction

Creating a simple CRUD interface

Using the Flask-Admin extension

Registering models with Flask-Admin

Creating custom forms and actions

WYSIWYG for textarea integration

Creating user roles

Chapter 9: Internationalization and Localization

Introduction

Adding a new language

Lazy evaluation and the gettext/ngettext functions

Global language-switching action

Chapter 10: Debugging, Error Handling, and Testing

Introduction

Setting up basic file logging

Sending e-mails on the occurrence of errors

Using Sentry to monitor exceptions

Debugging with pdb

Creating our first simple test

Writing more tests for views and logic

Nose library integration

Using mocking to avoid real API access

Determining test coverage

Using profiling to find bottlenecks

Chapter 11: Deployment and Post Deployment

Introduction

Deploying with Apache

Deploying with uWSGI and Nginx

Deploying with Gunicorn and Supervisor

Deploying with Tornado

Using Fabric for deployment

S3 storage for file uploads

Deploying with Heroku

Deploying with AWS Elastic Beanstalk

Application monitoring with Pingdom

Application performance management and monitoring with New Relic

Chapter 12: Other Tips and Tricks

Introduction

Full-text search with Whoosh

Full-text search with Elasticsearch

Working with signals

Using caching with your application

E-mail support for Flask applications

Understanding asynchronous operations

Working with Celery

Module 3

Chapter 1: Getting Started

Version control with Git

Python package management with pip

Dependency sandboxing with virtualenv

The beginning of our project

Summary

Chapter 2: Creating Models with SQLAlchemy

Setting up SQLAlchemy

Our first model

CRUD

Relationships between models

The convenience of SQLAlchemy sessions

Database migrations with Alembic

Summary

Chapter 3: Creating Views with Templates

Jinja's syntax

Creating our views

Flask WTForms

Summary

Chapter 4: Creating Controllers with Blueprints

Request setup, teardown, and application globals

Error pages

Class-based views

Blueprints

Summary

Chapter 5: Advanced Application Structure

The project as a module

Application factories

Summary

Chapter 6: Securing Your App

Setting up

Using the session

Flask Login

Summary

Chapter 7: Using NoSQL with Flask

Types of NoSQL databases

RDBMS versus NoSQL

MongoDB in Flask

Leveraging the power of NoSQL

Summary

Chapter 8: Building RESTful APIs

What is REST

Setting up a RESTful Flask API

GET requests

POST requests

PUT requests

DELETE requests

Summary

Chapter 9: Creating Asynchronous Tasks with Celery

What is Celery?

Setting up Celery and RabbitMQ

Creating tasks in Celery

Running Celery tasks

Monitoring Celery

Creating a reminder app

Creating a weekly digest

Summary

Chapter 10: Useful Flask Extensions

Flask Script

Flask Debug Toolbar

Flask Cache

Flask Assets

Flask Admin

Flask Mail

Summary

Chapter 11: Building Your Own Extension

Creating a YouTube Flask extension

Modifying the response with Flask extensions

Summary

Chapter 12: Testing Flask Apps

What are unit tests?

How does testing work?

Unit testing the application

User interface testing

Test coverage

Test-driven development

Summary

Chapter 13: Deploying Flask Apps

Deploying on your own server

Deploying on Heroku

Deploying on Amazon web services

Summary

Bibliography

Index

The users who browse this book also browse


No browse record.