Flask Internals
Commands we can execute to inspect a Flask web application via the CLI ( command-line interface).
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.
- π Flask Material Kit - source code
- π Flask Material Kit - LIVE Demo
Thanks for reading! For more resources, feel free to access:
- Flask Command-Line - published on Dev.to
- Flask - A list of useful βHOW TOβsβ Β