0%

Book Description

Build state-of-the-art web applications quickly and efficiently using Flask and related technologies with Python 3

Key Features

  • Explore Flask 1.0.3 and Python 3.7, along with useful insights into microservices
  • Get the most out of the powerful Flask framework and maintain the flexibility of your design choices
  • Write cleaner and maintainable code with the help of sample apps

Book Description

Flask, the lightweight Python web framework, is popular thanks to its powerful modular design that lets you build scalable web apps. With this recipe-based guide, you’ll explore modern solutions and best practices for Flask web development.

Updated to the latest version of Flask and Python 3, this second edition of Flask Framework Cookbook moves away from some of the old and obsolete libraries and introduces new recipes on cutting-edge technologies. You’ll discover different ways of using Flask to create, deploy, and manage microservices. This Flask Python book starts by covering the different configurations that a Flask application can make use of, and then helps you work with templates and learn about the ORM and view layers. You’ll also be able to write an admin interface and get to grips with debugging and logging errors. Finally, you’ll learn a variety of deployment and post-deployment techniques for platforms such as Apache, Tornado, and Heroku.

By the end of this book, you’ll have gained all the knowledge you need to confidently write Flask applications and scale them using standard industry practices.

What you will learn

  • Explore web application development in Flask, right from installation to post-deployment stages
  • Make use of advanced templating and data modeling techniques
  • Discover effective debugging, logging, and error handling techniques in Flask
  • Integrate Flask with different technologies such as Redis, Sentry, and MongoDB
  • Deploy and package Flask applications with Docker and Kubernetes
  • Design scalable microservice architecture using AWS Lambda continuous integration and continuous deployment

Who this book is for

If you are a web developer who wants to learn more about developing scalable and production-ready applications in Flask, this is the book for you. You’ll also find this book useful if you are already aware of Flask's major extensions and want to use them for better application development. Basic Python programming experience along with basic understanding of Flask is assumed.

Downloading the example code for this ebook: You can download the example code files for this ebook on GitHub at the following link: https://github.com/PacktPublishing/Flask-Framework-Cookbook-Second-Edition. If you require support please email: [email protected]

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Flask Framework Cookbook Second Edition
  3. About Packt
    1. Why subscribe?
  4. Contributors
    1. About the author
    2. About the reviewers
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Sections
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Get in touch
      1. Reviews
  6. Flask Configurations
    1. Setting up our environment with virtualenv
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    2. Handling basic configurations
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Configuring using class-based settings
      1. How to do it...
      2. How it works...
    4. Organizing static files
      1. How to do it...
      2. How it works...
      3. There's more...
    5. Being deployment-specific with instance folders
      1. How to do it...
      2. How it works...
    6. Composition of views and models
      1. How to do it...
      2. How it works...
      3. See also
    7. Creating a modular web app with blueprints
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    8. Making a Flask app installable using setuptools
      1. How to do it...
      2. How it works...
      3. See also
  7. Templating with Jinja2
    1. Bootstrapping the recommended layout
      1. Getting ready
      2. How to do it...
      3. How it works...
    2. Implementing block composition and layout inheritance
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Creating a custom context processor
      1. How to do it...
    4. Creating a custom Jinja2 filter
      1. How to do it...
      2. How it works...
      3. See also
    5. Creating a custom macro for forms
      1. Getting ready
      2. How to do it...
    6. Advanced date and time formatting
      1. Getting ready
      2. How to do it...
      3. See more
  8. Data Modeling in Flask
    1. Creating an SQLAlchemy DB instance
      1. Getting ready
      2. How to do it...
      3. There's more...
      4. See also
    2. Creating a basic product model
      1. How to do it...
      2. How it works...
      3. See also
    3. Creating a relational category model
      1. How to do it...
      2. See also
    4. Migrating databases using Alembic and Flask-Migrate
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Indexing model data with Redis
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Opting for the NoSQL way with MongoDB
      1. Getting ready
      2. How to do it...
      3. See also
  9. Working with Views
    1. Writing function-based views and URL routes
      1. Getting ready
      2. How to do it...
        1. A simple GET request
        2. A simple POST request
        3. A simple GET/POST request
      3. How it works...
      4. There's more...
    2. Writing class-based views
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Implementing URL routing and product-based pagination
      1. Getting ready
      2. How to do it...
        1. Adding pagination to applications
      3. See also
    4. Rendering to templates
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Dealing with XHR requests
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Using decorators to handle requests beautifully
      1. Getting ready
      2. How to do it...
      3. See also
    7. Creating custom 404 and 500 handlers
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Flashing messages for better user feedback
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Implementing SQL-based searching
      1. Getting ready
      2. How to do it...
      3. How it works...
  10. Webforms with WTForms
    1. Representing SQLAlchemy model data as a form
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    2. Validating fields on the server side
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    3. Creating a common forms set
      1. How to do it...
      2. How it works...
    4. Creating custom fields and validation
      1. How to do it...
      2. How it works...
      3. There's more...
    5. Creating a custom widget
      1. How to do it...
      2. How it works...
      3. See also
    6. Uploading files via forms
      1. How to do it...
      2. How it works...
    7. Protecting applications from cross-site request forgery (CSRF)
      1. How to do it...
      2. How it works...
  11. Authenticating in Flask
    1. Creating a simple session-based authentication
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    2. Authenticating using the Flask-Login extension
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Using Facebook for authentication
      1. Getting started
      2. How to do it...
      3. How it works...
    4. Using Google for authentication
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Using Twitter for authentication
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Authenticating with LDAP
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  12. RESTful API Building
    1. Creating a class-based REST interface
      1. Getting ready
      2. How to do it...
      3. How it works...
    2. Creating an extension-based REST interface
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Creating a complete RESTful API
      1. Getting ready
      2. How to do it...
      3. How it works...
  13. Admin Interface for Flask Apps
    1. Creating a simple CRUD interface
      1. Getting ready
      2. How to do it...
      3. How it works...
    2. Using the Flask-Admin extension
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Registering models with Flask-Admin
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Creating custom forms and actions
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Using a WYSIWYG editor for textarea integration
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Creating user roles
      1. Getting ready
      2. How to do it...
      3. How it works...
  14. Internationalization and Localization
    1. Adding a new language
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    2. Implementing lazy evaluation and the gettext/ngettext functions
      1. Getting ready
      2. How to do it...
    3. Implementing the global language switching action
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  15. Debugging, Error Handling, and Testing
    1. Setting up basic file logging
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    2. Sending emails on the occurrence of errors
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Using Sentry to monitor exceptions
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Debugging with pdb
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Creating our first simple test
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Writing more tests for views and logic
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Nose library integration
      1. Getting ready
      2. How to do it...
      3. See also
    8. Using mocking to avoid real API access
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    9. Determining test coverage
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    10. Using profiling to find bottlenecks
      1. Getting ready
      2. How to do it...
      3. How it works...
  16. Deployment and Post-Deployment
    1. Deploying with Apache
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    2. Deploying with uWSGI and Nginx
      1. Getting ready
      2. How to do it...
      3. See also
    3. Deploying with Gunicorn and Supervisor
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Deploying with Tornado
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Using S3 storage for file uploads
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Deploying with Heroku
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Deploying with AWS Elastic Beanstalk
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Managing and monitoring application performance with New Relic
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  17. Microservices and Containers
    1. Containerization with Docker
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    2. Orchestrating containers with Kubernetes
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Going serverless with Zappa on AWS Lambda
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  18. Other Tips and Tricks
    1. Implementing full-text search with Whoosh
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    2. Implementing full-text search with Elasticsearch
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Working with signals
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Using caching with your application
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Implementing email support for Flask applications
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Understanding asynchronous operations
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Working with Celery
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  19. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think
3.81.13.254