Things which aren't magic – Flask and app.route
1–10 of 35 posts
Re: Things which aren't magic – Flask and app.route
#2Re: Things which aren't magic – Flask and app.route
#3On a more relevant note, thanks for sharing this. It's always nice to read an explanation from somebody patient enough to not skip over a bunch of steps in the middle and avoid losing newbs like me.
Re: Things which aren't magic – Flask and app.route
#4That. Things _that_ aren't magic. On a more relevant note, thanks for sharing this. It's always nice to read an explanation from somebody patient enough to not skip over a bunch of steps in the middle and avoid losing newbs like me.
On a more relevant note, I agree, this is a great article. :) (I'd already known in theory how decorators work, but this was a very clear presentation, and I hadn't quite thought through the part about only needing a reference to the unmodified function, so it was useful to see that trick spelled out.)
Re: Things which aren't magic – Flask and app.route
#5Given my understanding from the article, there's a hole: how does serving route "/" know to call that function if (given my assumptions) the @app.route("/") decoration is not executed until the function it decorates is called?
Re: Things which aren't magic – Flask and app.route
#6What's throwing me off -- and I'm sure it's something trivial I'm not seeing -- is how we add the functions to the routes dictionary. When is the decorator's code actually executed? Is that done at import time? My assumption is that its code is executed when its counterpart is called, though clearly that mustn't be the case. Given my understanding from the article, there's a hole: how does serving route "/" know to c…
Re: Things which aren't magic – Flask and app.route
#7What's throwing me off -- and I'm sure it's something trivial I'm not seeing -- is how we add the functions to the routes dictionary. When is the decorator's code actually executed? Is that done at import time? My assumption is that its code is executed when its counterpart is called, though clearly that mustn't be the case. Given my understanding from the article, there's a hole: how does serving route "/" know to c…
The return value of the function is a decorator, so then the @ syntax applies it to the succeeding function. In the process of applying the decorator, it adds the route to the dictionary. That's also on module import.
Re: Things which aren't magic – Flask and app.route
#8What's throwing me off -- and I'm sure it's something trivial I'm not seeing -- is how we add the functions to the routes dictionary. When is the decorator's code actually executed? Is that done at import time? My assumption is that its code is executed when its counterpart is called, though clearly that mustn't be the case. Given my understanding from the article, there's a hole: how does serving route "/" know to c…
Plain decorators work how you expect but generators are different. The decorator generator is called at import time, which is when the association between the route and the function is stored.
Edit:Sorry. I did not notice the term decorator generator in the article. Thanks for the explanation
Re: Things which aren't magic – Flask and app.route
#9That. Things _that_ aren't magic. On a more relevant note, thanks for sharing this. It's always nice to read an explanation from somebody patient enough to not skip over a bunch of steps in the middle and avoid losing newbs like me.
"Then saith he unto them, Render therefore unto Caesar the things which are Caesar's; and unto God the things that are God's."
Clearly Flask is Caesar's ;-)