In Chapter 1, Getting Started, we created a basic manage script with the Flask extension Flask Script to allow easy running of the server and debugging with the shell. In this chapter, we will cover the features that were not covered in that basic introduction.
In Flask Script, you can create custom commands to be run within the application context. All that is needed is to create a command to decorate a normal Python function with a decorator function provided by Flask Script. For example, if we wanted a task that would return the string "Hello, World!" we would add the following to manage.py
:
@manager.command def test(): print "Hello, World!"
From the command line, the test
command can now be run using the following:
$ python manage.py test Hello, World!
Delete the test command, and let's create a simple command to help set up new developers on our application by creating their SQLite database and filling it with test data. This command is partially lifted from the script...