samedi 27 octobre 2018

How can python find decorated functions within it?

In the following code how does app.run() find that hello() exists? I browsed the code and couldn't find the answer. I think the hello() doesn't get added to a list of routes until it is called, but how does it get called?

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()

I'm not interested in Flask in particular. I'd just like to implement something similar myself.

What is this design pattern called?

Aucun commentaire:

Enregistrer un commentaire