Accept Credit Card Payments in Flask with Stripe Checkout

Posted by
on under

In this article I'm going to show you how to implement an order page for your Flask application that you can use to sell products or services online. The solution I'm going to present to you uses Stripe Checkout, a secure and easy to use credit card charging service that integrates nicely with Flask.

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 and answer questions? Become a Patron!

Flask Mega-Tutorial Update: Flask 2.0 and more!

Posted by
on under

I'm excited to share that I've completed a revision of the Flask Mega-Tutorial to keep it in line with new releases of Flask, Python and third-party dependencies.

Flask Mega-Tutorial

To celebrate this update, you can purchase the paid version of this course with a $10 USD discount (this offer is valid through the rest of July 2021). If you are interested in this offer, use the FLASK2 promotional code at checkout, or click here to go directly to the order page with the coupon added. Thank you!

Beautiful Interactive Tables for your Flask Templates

Posted by
on under

Rendering a table with data in a Flask template is a relatively simple task when the table is short, but can be incredibly hard for larger tables that require features such as sorting, pagination and searching. In this article I'm going to show you how to integrate the dataTables.js library in your templates, which will allow you to create fully featured tables with ease!

How to Get the Code

How to Dockerize a React + Flask Project

Posted by
on under

This is the fourth article in my series about working with a combined Flask and React project. In this part I'm going to cover how to deploy the application in Docker containers.

Dynamically Update Your Flask Web Pages Using Turbo-Flask

Posted by
on under

How can you update a part of a web page dynamically, without the user having to hit the refresh button on the browser?

This is a question that is frequently asked on the Internet. If you have some knowledge of JavaScript this is relatively easy to do, more so if you use a front end web framework such as React or Vue. But what if you have a standard web application written in Flask and Jinja templates?

In this article I'm going to introduce you to my Turbo-Flask extension, which will allow your Flask application to easily push asynchronous page updates to the browser, without having to write any JavaScript code. In the screenshot below, note how the CPU load numbers update without the user doing anything.

Turbo-Flask Demo Application

Why do we pass __name__ to the Flask class?

Posted by
on under

When you learn Flask, you are told to create your Flask application instances by passing __name__ as the first argument to the Flask class. Most developers do this without thinking, and without knowing what it achieves.

In this article we are going to look at Flask(__name__) in depth. By the end you will not only have a full understanding of this pattern, but you will also know when to deviate from it and pass other values.

How to Deploy a React-Router + Flask Application

Posted by
on under

This is the third article in my "React + Flask" series, in which I discuss applications that combine a Flask API server with a React single-page application. This time I'm going to show you how to work with the popular React-Router library for React, and in particular how this library affects the production deployment of the application.

This is the third article in my "React + Flask" series. Make sure you read the first and second parts, as this part builds on the project built up to this point.

Video: How To Fix an Internal Server Error in Flask

Posted by
on under

In this beginner level video I explain what steps you need to take when you get an Internal Server Error in your Flask application.

Fixing ALTER TABLE errors with Flask-Migrate and SQLite

Posted by
on under

If you've done any work with SQLite databases you surely know that this database is very limited in terms of making changes to the database schema. When working with a migration framework such as Flask-Migrate, it is common to end up with migration scripts that fail to upgrade or downgrade just because they need to remove or modify a column in a table, something that SQLite does not support.

In this article I'm going to discuss this limitation of the SQLite database, and show you a workaround that is specific to Flask-Migrate and Alembic.

Run Your Flask Regularly Scheduled Jobs with Cron

Posted by
on under

A common need of web applications is to have a periodically running task in the background. This could be a task that imports new data from third party sources, or maybe one that removes revoked tokens from your database once they have expired. In this and many other situations you are faced with the challenge of implementing a task that runs in the background at regular intervals.

This is a pattern that many people ask me about. I've seen implementations that are based on the APScheduler package, on Celery, and even homegrown solutions built inside a background thread. Sadly none of these options are very good. In this article I'm going to show you what I believe is a very robust implementation that is based on the Flask CLI and the cron service.