Skip to content

[Flask] Using Flask Script to run commands while the application is running

Radu Raicea edited this page Sep 30, 2017 · 1 revision

Flask-Script is used to run commands while the application is already running. It has many usages like: running unit tests, modifying the database, debugging and more.

The official documentation can be found here:

https://flask-script.readthedocs.io/en/latest/

Defining a command

The command must be defined in flask/manage.py as follows

@manager.command
def name_of_command():
    # statements to be called

Running the command

First, run the web application in a shell. Second, open a new shell and run the following command, using the same name as the function defined earlier instead of name_of_command

docker-compose run --rm flask python manage.py name_of_command