Flask Web Development In Action took over a year, during which time, in addition to writing 5 project examples and writing, I also spent some time working with the Python libraries (mainly Flask extensions) covered in the book. This article summarizes some of the changes that writing the book has made to the entire Flask community.

Flask’s first book in the country

There have been a few books about Flask in the country, but they are all in passing, not exactly Flask books. Therefore, this book is arguably the first Flask book in the country and it is a pleasure to bring one to the Flask community in the country. Hopefully this book will inspire more people to learn about and use Flask and contribute to the community.

Complete multiple projects

There are always a variety of problems encountered when actually introducing and using a library, of which there are two main types:

  • Bug
  • Imperfect usage or implementation
Bugs need to be dealt with. For imperfect usage and implementation, if the original code is used, it will not be easy for readers to understand, and also need to add a lot of unnecessary content in the book. So, I prefer to make the code a little better.

I would feel very uncomfortable writing an imperfect implementation in a book. For example, WTForms itself is a language that supports setting built-in error messages, which we can set to Chinese instead of writing error messages manually. In flask-WTF, however, the built-in translation cannot be used without flask-Babel because the related methods are internally overwritten. Here’s the problem: It would not be appropriate to introduce flask-Babel and i18n in Chapter 4, which is already planned for Chapter 10.

For this reason, the book arrangement could not be changed, so the internal implementation of Flask-WTF had to be adjusted, hence the PR. Selenium does not provide the same import interface as Chrome, even though Firefox supports the Headless mode. Flask-oauthlib, access tokens can only be passed in using tuples or dictionary types, not string variables, which are more intuitive…

Here are some of the open source contributions submitted during writing:

  • GitHub-Flask:
    Support API endpoint with a leading slash
  • Flask-OAuthlib:
    Add support for string type token
  • Selenium:
    Add import statement for FirefoxOptions
  • Authlib:
    add google_fetch_user function
  • Flask-SocketIO:
    Add missing json argument in send() function
  • Flask -oauthlib: Add support for String type token
  • OAuthlib:
    Check access token in self.token dict
  • Flask-Moment:
    Add auto-detect locale support
  • Flask-Whooshee: Fix Unicode decode error on Python2
  • Pipenv:
    Add tips for Supervisor user
  • Flask-WTF:
    Add support to change message language
  • Werkzeug: Reloader: Force the key of environment variable into string type
  • Flask:
    19 merged PRs, mostly are documentation fix
Of course, the list could be even longer if you add in other documentation updates that don’t make much sense.

It is worth noting that the PR of Werkzeug has a bug that has bothered me for a long time. At first I blamed the problem on python-Dotenv and created a PR (
# 101), but the maintainer did not reply. It was later studied again and found that it could be solved directly inside Werkzeug, so it was created
# 1320Lepture was replaced with a better implementation (
# 1321). However, the PR created in Python-Dotenv contributed to the PR in Pipenv (
# 2386).


Push for new releases

In addition to having PR merged, these projects should also release new releases so that they can be used by readers once the project source code is made public. Flask-oauthlib, Flask-Whooshee and Flask-Moment have all been released with new versions, thanks to my push.

Most of the other projects, with the exception of Werkzeug, released new versions throughout the writing span. Of particular importance is Flask’s 1.0 release. From the beginning of the book, I used the main branch code directly. In the book, I wrote the version number as 0.13. If Flask didn’t release a new version, I’d be in the awkward position of either sticking with the main branch code, which might change and make the book unreliable; Or an old version, which may soon be in danger of becoming obsolete. Fortunately, by the end of April, as the writing was nearing its end, a new version 1.0 was released.

Four Flask expansions

Flask-Bootstrap is currently in a bad state of maintenance: its last release was January 17, its last merge commit was March 17, and it has been a long time since it handled PR and issues.

The original project had many problems: The Jinja syntax was not standard, the built-in base template introduced unnecessary complexity, and paging macros did not support passing IN URL fragment values. Other than that, the main reason I decided to write a new extension to replace it was because it didn’t support Bootstrap 4, and I couldn’t accept introducing such an outdated project into the book.

To solve these problems, we have to write bootstrap-flask. By the time the decision was finally made to write an alternative extension, the book was two-thirds complete and much of the old content and source code had to be rewritten. Migrating the manuscript and source code from flask-Bootstrap and Bootstrap3 to Bootstrap4 was a painful process that I still remember very well…

For some blank areas, I wrote three extensions to simplify integration:

  • Flask-Avatars: Head treatment
  • Flask-dropzone: integrates with Dropzone.js and provides client processing for file uploading
  • Flask-ckeditor: Integrates rich text editor CKEditor

Five Flask open source projects

There are only a handful of Flask open source projects out there, and aside from the two Flask samples, there are only two Miguel Grinberg programs. This book comes with five relatively complete open source projects with all dependencies based on the latest version (strictly speaking, the first program is simple and can be excluded) :

  • SayHello: Message board
  • Bluelog: Personal blog
  • Albumy: social app for pictures
  • Todoism: To-do list
  • CatChat