Ever used Flask and wondered what the
@route nonsense is all about?
More drum rolls
A decorator is a function which takes another function as an argument, does some work around it, and returns a new function.
Let's look at a standard decorator.
@login_required def home(): # some stuff
This is just syntactic sugar for
def home(): # some stuff home = login_required(home)
Don't worry, we'll start with how functions in Python work, and build on that. We will then make our own decorators, by the end, hopefully, we will build a nano framework (á la Flask, except more micro).
What do you need?
- A running Python shell
- Nothing else.
We'll start at 6PM on Wednesday, October 28, in C01.