Hello! This article presents a few commands we can execute inside Flask Shell that might help us understand the structure and the business logic of a legacy web app. We might need this when we start working on a new project designed or coded in the past or just our own web app is getting bigger.
Thank for reading!
👉 Flask - Short introduction
👉 Flask CLI (command line interface)
👉 List Registered Models
👉 List Table Columns
✨ Flask Intro
Flask is a lightweight WSGI web application framework. It is designed to make getting started quick and easy, with the ability to scale up to complex applications. Getting started with Flask is pretty easy. Once we have Python3 installed and a modern code editor like VsCode or Atom we can write our first web app.
The above command will install the latest version of Flask via PIP, the official package manager for Python.
Once the file is saved, we can invoke Flask magic using the command:
✨ Flask CLI
Flask provides a convenient way to interact with all app internals via a simple command-line interface powered by the Click package. To invoke the CLI, we need to execute the following command:
👉 Flask CLI - List Routes
👉 Flask CLI - Print static folder
👉 Flask CLI - Print templates folder
👉 Flask CLI - List Database Models
The db object holds the SqlAlchemy interface and we will pull the information via this object.
👉 List All Tables
In my project, we have a single Users table - let's take a look at the definition:
👉 Flask CLI - List Table Columns
✨ Free Sample - Material Kit
Curious minds can experiment and play with all the above commands using this open-source sample provided with database, authentication, SqlAlchemy ORM, and Docker support - Flask Material Kit.