The Flask Mega-Tutorial, Part IV: Database

Posted by
on under

This is the fourth installment of the Flask Mega-Tutorial series, in which I'm going to tell you how to work with databases.

The Flask Mega-Tutorial, Part III: Web Forms

Posted by
on under

This is the third installment of the Flask Mega-Tutorial series, in which I'm going to tell you how to work with web forms.

The Flask Mega-Tutorial, Part II: Templates

Posted by
on under

In this second installment of the Flask Mega-Tutorial series, I'm going to discuss how to work with templates.

The Flask Mega-Tutorial, Part I: Hello, World!

Posted by
on under

Welcome! You are about to start on a journey to learn how to create web applications with Python and the Flask framework. In this first chapter, you are going to learn how to set up a Flask project. By the end of this chapter you are going to have a simple Flask web application running on your computer!

Some More To Talk About Flask

Posted by
on under

A few days ago I published a harsh critique of the Flask's team practices with regards to releases, versioning and especially about their weak backwards compatibility track record. This generated a bit of a stir and lots of people, including members of the Flask core development itself, have voiced their opinions.

I'm going to start by admitting that even though I have received some support, there has been a lot of push back as well. I really have no problem with this, as I don't hide from criticism. In this follow up article I'm going to talk about the good and the bad takes that resulted from my blog post, but I especially want to dissect the opposing views.

We Have To Talk About Flask

Posted by
on under

Flask 3.0 was released on September 30th, 2023, along with a parallel 3.0 release of Werkzeug, its main dependency. That day, the Flask-Login extension, one of the most popular of all Flask extensions, stopped working due to a backwards incompatible change introduced in Werkzeug. It is October 19th when I'm writing this, and Flask-Login remains broken. As a result, any person using my Flask Mega-Tutorial will hit issues, because my tutorial uses Flask-Login. Not only that, every Flask tutorial that features Flask-Login, from every author, in every language, in written or video form, is going to fail for as long as this problem remains. Hard to believe, right? (Update: a fixed release of Flask-Login was published on October 30th)

If this was the first occurrence of something of this nature in the Flask community, I would hope it would serve as a lesson for the Flask maintainers to learn from and avoid in the future. Sadly, this happens pretty much every time there is a major release of Flask, and sometimes minor ones too. Why does this happen? How can it be avoided? In this article I'll try to make an assessment of the current situation and how it can be prevented going forward.

There is now an update to this post as well.

OAuth Authentication with Flask in 2023

Posted by
on under

A long time ago I wrote a tutorial on how to add logins with a social network to your Flask application, using the OAuth protocol. It's been almost 9 years since I wrote that article, and believe it or not, the OAuth protocol continues to be well supported by all major players including Twitter, Facebook, Google, GitHub and many more.

But of course, 9 years is a very long time in tech. Even though not much has changed in terms of how this method of authentication works, some of the packages that I've used back then have had major upgrades, while others have become unmaintained, so an update is due.


Flask + OAuth 2.0 Demo

Beautiful Flask Tables, Part 2

Posted by
on under

It's been almost a year since I published my Beautiful Interactive Tables for your Flask Templates article, in which I showed a few example tables, rendered from a standard Flask and Jinja template, with some JavaScript help.

I have received a good amount of feedback on my proposed solutions. In this article I'm going to refresh my table examples to address the two most frequently requested improvements.

API Authentication with Tokens

Posted by
on under

In this article I'm going to show you a few common patterns for client authentication based on tokens, and how can they be implemented in a Python API back end. This method of authentication works well for rich clients, like JavaScript-based front end applications running in the browser, or perhaps a command-line (CLI) application.

I have written about Authentication several times on this blog, so this article is a bit different. Since I have already provided a few authentication projects in previous articles and in my open source projects, in this article I'm going to go over all the considerations you have to take into account when deciding how to best implement authentication for your own API project.

This article was voted by my supporters on Patreon. Would you like to support my work, and as a thank you be able to vote on my future articles and also have access to a chat room where I hang out? Become a Patron!

Add a WebSocket Route to your Flask 2.x Application

Posted by
on under

The WebSocket protocol was standardized 10 years ago (in 2011, can you believe it?) so I'm sure for many of it you does not need an introduction. But in case you are not familiar with it, WebSocket is an extension to the HTTP protocol that provides a permanent, bi-directional communication channel between a client and the server, where both sides can send and receive data in real time, free of the constraints of the request/response cycle of HTTP.

Flask, being a minimalist web framework, does not have WebSocket support built-in. The old Flask-Sockets extension, which has not been maintained in the last few years, provided support for this protocol. My own Flask-SocketIO extension has also been a favorite, but this is Socket.IO, which is a more complex protocol that combines WebSocket and HTTP.

The good news is that if you are using Flask 2 you now have a new extension (also created by myself) called Flask-Sock, which provides modern WebSocket support for your application. In this article I'm going to show you how to work with this extension.

This article was voted by my supporters on Patreon. Would you like to support my work, and as a thank you be able to vote on my future articles and also have access to a chat room where I hang out? Become a Patron!