-1

Apologies if this is not a valid question.

I can run my flask app by taking in an optional argument on my command line as follows:

python main.py reset

For my case, the reset argument clears all rows in my sqlite database attached to my web app. Meaning I can start the app with a fresh database slate.

However, during development with debug=True, as the app runs and i save my files, it seems that the above CL command gets called along with the optional argument, resulting in my database constantly being cleared.

The obvious workaround is to rerun the app without the optional argument after I cleared my database so that the debugging mode will not call the optional argument.

I was wondering if this considered to be a "bug", or its simply how the debugging feature works and there's nothing that can be done to change this?

Ken
  • 49
  • 5

1 Answers1

0

I'm not exactly sure why reset is getting called when you don't expect it, I'd have to see main.py in the debugger to figure that out.

But Flask has a built in way of making custom commands for exactly what your use case is resetting the database, or filling it with dummy data etc.

from flask import Flask

app = Flask(__name__)

@app.cli.command("resetdb")
def reset_db():
    # delete rows

$ flask resetdb

https://flask.palletsprojects.com/en/2.2.x/cli/#custom-commands

barryodev
  • 509
  • 3
  • 11