#100DaysOfCode in Python Transcripts
Chapter: Days 22-24: Decorators
Lecture: Examples of real life decorators
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Okay, that concludes the basic coverage of decorators in Python. In this section I provide you some more pointers to study some more decorators today.
0:11
I did an article on Twilio, and in this app I used a login required decorator to check if the user is logged in. And you can see that in the code.
0:22
This is what you already saw in this lesson. The wraps, and the wrapper. It takes the arguments and just checks if login is in the session.
0:31
If so, return to function. If not, do a flash message and redirect to the login page. That's similar to what Django is doing,
0:41
which, I pointed to the source. You can check that out as well. There's some more stuff going on so I challenge you to take a look at this code
0:48
if you have time left today. And on PyBites we did an article, "Learning Python Decorators By Example," which partly overlaps with
0:57
what you have seen in the lesson so far, but there are also some more examples for caching, some more decorators in the wild.
1:05
And I point you to another article. Sometimes you need a decorator that takes arguments like speed decorator that takes seconds
1:14
and it's not always straightforward how optional arguments work so I wrote an article about that. So if you still have time left today
1:20
and you want to know decorators a bit more in detail you can read this article as well. And that concludes the lesson of Day 1.