Flask Framework Cookbook 3rd Ed.

Enhance your Flask skills with advanced techniques and build dynamic, responsive web applications

Shalabh Aggarwal

Publisher: Packt, 2023, 295 pages

ISBN: 978-1-80461-110-4

Keywords: Python, Web Programming

Last modified: Nov. 13, 2023, 3:45 p.m.

Discover what makes Flask, the lightweight Python web framework, popular, as you delve into its modular design that enables the development of scalable web apps- With this practical guide, you'll explore modern solutions, recommended design patterns, and best practices for Flask web development.

Updated to the latest version of Flask and Python, this third edition of the Flask Framework Cookbook moves away from the outdated libraries, updates content to incorporate new coding patterns, and introduces recipes for the latest tools. You'll explore different ways to integrate with GPT to build AI-ready Flask applications. The book starts with an exploration of Flask application configurations and then guides you through working with templates and understanding the ORM and view layers. You'll also be able to write an admin interface and get to grips with testing using the factory pattern, debugging, and logging errors. Then you'll discover different ways of using Flask to create, deploy, and manage microservices using AWS, GCP, and Kubernetes. Finally, you'll gain insights into various deployment and post-deployment techniques for platforms such as Apache, Tornado, and Datadog.

By the end of this book, you'll have acquired the the knowledge necessary to write Flask applications that cater to a wide range of use cases in the best possible way and scale them using standard industry practices.

    • Preface
  • Part 1: Flask Fundamentals
    1. Flask Configurations
      • Technical requirements
      • Setting up a virtual environment
      • Handling basic configurations
      • Configuring using class-based settings
      • Organizing static files
      • Being deployment specific with the instance folder
      • Creating a modular web app with blueprints
      • Making a Flask app installable using setuptools
    2. Templating with Jinja2
      • Technical requirements
      • Bootstrapping the standard layout
      • Creating a custom context processor
      • Creating a custom Jinja filter
      • Creating a custom macro for forms
      • Advanced date and time formatting
    3. Data Modeling in Flask
      • Creating an SQLAlchemy DB instance
      • Creating a basic product model
      • Migrating databases using Alembic and Flask-Migrate
      • Indexing model data with Redis
      • Opting for the NoSQL way with MongoDB
    4. Working with Views
      • Writing function-based views and URL routes
      • Writing class-based views
      • Implementing URL routing and product-based pagination
      • Rendering to templates
      • Dealing with XHR requests
      • Using decorator to handle requests beautifully
      • Creating custom 4xx and 5xx error handlers
      • Flashing messages for better user feedback
      • Implementing SQL-based searching
  • Part 2: Flask Deep Dive
    1. Webforms with WTForms
      • Representing SQLAlchemy model data as a form
      • Validating fields on the server side
      • Creating a common forms set
      • Creating custom fields and validations
      • Creating a custom widget
      • Uploading files via forms
      • Protecting applications from CSRF
    2. Authenticating in Flask
      • Creating a simple session-based authentication
      • Authenticating using the Flask-Login extension
      • Using Facebook for authentication
      • Using Google for authentication
      • Using Twitter for authentication
      • Authentication with LDAP
    3. RESTful API Building
      • Creating a class-based REST interface
      • Creating an extension-based REST interface
      • Creating a complete RESTful API
    4. Admin Interface for Flask Apps
      • Creating a simple CRUD interface
      • Using the Flask-Admin extension
      • Registering models with Flask-Admin
      • Creating custom forms and actions
      • Using a WYSIWYG editor for textarea integration
      • Creating user roles
    5. Internationalization and Localization
      • Adding a new language
      • Implementing lazy evaluation and the gettext/ngettext functions
      • Implementing the global language-switching action
  • Part 3: Advanced Flask
    1. Debugging, Error Handling, and Testing
      • Setting up basic file logging
      • Sending e-mails on the occurrence of errors
      • Using Sentry to monitor exceptions
      • Debugging with pdb
      • Creating application factories
      • Creating the first simple test
      • Writing more tests for views and logic
      • Integrating the nose2 library
      • Using mocking to avoid external API access
      • Determining test coverage
      • Using profiling to find bottlenecks
    2. Deployment and Post Deployment
      • Deploying with Apache
      • Deploying with uWSGI and Nginx
      • Deploying with Gunicorn and Supervisor
      • Deploying with Tornado
      • S3 storage for file uploads
      • Managing and monitoring application performance with New Relic
      • Infrastructure and application monitoring with Datadog
    3. Microservices and Containers
      • Containerization with Docker
      • Orchestrating containers with Kubernetes
      • Going serverless with Google Cloud Run
      • Continuous deployment with GitHub Actions
    4. GPT with Flask
      • Technical requirements
      • Automating text completion using GPT
      • Implementing chat using GPT (ChatGPT)
      • Generating images using GPT
    5. Additional Tips and Tricks
      • Implementing full-text search with Elasticsearch
      • Working with signals
      • Using caching with your application
      • Implementing E-mail support
      • Understanding asynchronous operations
      • Working with Celery

Reviews

Flask Framework Cookbook

Reviewed by Roland Buresund

Decent ****** (6 out of 10)

Last modified: Nov. 13, 2023, 3:47 p.m.

A very recent updated book on an already decent book, and it still going strong. Misses the depths, but you can't get everything.

Comments

There are currently no comments

New Comment

required

required (not published)

optional

required

captcha

required