You are here: Home Books f Flask Framework Cookbook
Document Actions

Flask Framework Cookbook

Quick Answers to Common Problems

Shalabh Aggarwal

Publisher: Packt, 2014 , 242 pages

ISBN: 978-1-78398-340-7

Keywords: Python, Web Programming

Synopsis:

Toggle Synopsis

Flask Framework Cookbook takes you through a number of recipes that will help you understand the power of Flask and its extensions. You will start by seeing the different ways of configurations that a Flask application can make use of. You will learn how to work with templates and learn about the ORM and view layers. You will see how to write an admin interface followed by the debugging and logging of errors. Finally, you will learn about different deployment and post-deployment techniques on platforms such as Apache, Tornado, and Heroku.

By the end of this book, you will have gained all the knowledge required to write Flask applications in the best possible way, and scale them with best practices.

Table of Contents:

Toggle Table of Contents

  • Preface
  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
  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
  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
  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
  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
  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
  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
  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
  9. Internationalization and Localization
    • Introduction
    • Adding a new language
    • Lazy evaluation and the gettext/ngettext functions
    • Global language-switching action
  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
  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
  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

Reviews:

Flask Framework Cookbook

by Roland Buresund last modified 2015-12-21 23:27

Rating: ****** (Decent)

Gives a lot of small recipes, that are interesting and some even very useful.

It lacks a bit of depth, but it tries to compensate by cover a lot of areas instead.

Worth the money spent on it.


Powered by Plone, the Open Source Content Management System

This site conforms to the following standards: