Book Image

Full-Stack Flask and React

By : Adedeji
3.5 (2)
Book Image

Full-Stack Flask and React

3.5 (2)
By: Adedeji

Overview of this book

Developing an interactive, efficient, and fast enterprise web application requires both the right approach and tooling. If you are a web developer looking for a way to tap the power of React’s reusable UI components and the simplicity of Flask for backend development to develop production-ready, scalable web apps in Python, then this book is for you. Starting with an introduction to React, a JavaScript library for building highly interactive and reusable user interfaces, you’ll progress to data modeling for the web using SQLAlchemy and PostgreSQL, and then get to grips with Restful API development. This book will aid you in identifying your app users and managing access to your web application. You’ll also explore modular architectural design for Flask-based web applications and master error-handling techniques. Before you deploy your web app on AWS, this book will show you how to integrate unit testing best practices to ensure code reliability and functionality, making your apps not only efficient and fast but also robust and dependable. By the end of this book, you’ll have acquired deep knowledge of the Flask and React technology stacks, which will help you undertake web application development with confidence.
Table of Contents (21 chapters)
1
Part 1 – Frontend Development with React
9
Part 2 – Backend Development with Flask

Creating custom error pages

In addition to error handlers in Flask, you can also create custom error pages that provide a better user experience. When an error occurs in your application, the error handler can return a custom error page with information about the error, instructions for resolving the issue, or any other content that may be appropriate.

To create a custom error page in Flask, simply create an error handler as described in the preceding section and return a JSON response that contains the content for the error page.

For instance, let’s take a look at the JSON response containing a custom error message in the following code:

@app.errorhandler(404)def not_found(error):
    return jsonify({'error': 'Not found'}), 404

The preceding code returns a JSON response containing an error message, along with the corresponding HTTP error codes, when a 404 error occurs. Let’s define the React frontend to handle the UI...