Files
055-higher-lower/docs/wiki/Lecture-5-Advanced-Decorators.md
Tirsvad 1887fc347f Add lecture screenshots, README step overview and the three-language wiki
Screenshots are captured in a Docker container with a headless browser.

Task: MIL-004#1
Task: MIL-004#2
Task: MIL-004#3
Task: MIL-004#4
Task: MIL-004#5
2026-11-06 12:42:20 +08:00

834 B

English · Dansk · Bahasa Melayu

Lecture 5: Advanced decorators

Angela is logged in and gets a post, Bob is not and gets none

Code: src/higher_lower/presentation/lectures/step_05_authenticated.py.

What we gained

  • *args collects positional arguments and **kwargs collects keyword arguments, so a decorator works for any function.
  • is_authenticated reads the user from the arguments and runs the function only when user.is_logged_in is true.
  • A decorator can control whether a function runs at all, not only change its result.
  • The same pattern protects any function that needs a logged-in user.