Add decorator after @Get
See original GitHub issueIssue Analytics
- State:
- Created 6 years ago
- Comments:19 (5 by maintainers)
Top Results From Across the Web
How can one attach a decorator to a function "after the fact" in ...
You imported sqrt into your module, just apply the decorator there in your own global namespace: sqrt = print_args_decor(sqrt).
Read more >Primer on Python Decorators
In this introductory tutorial, we'll look at what Python decorators are and how to create and use them.
Read more >How to Create and Use Decorators in Python With Examples
We use a decorator by placing the name of the decorator directly above the function we want to use it on. You prefix...
Read more >using decorator functions in Python - ZetCode
Decorators are functions which decorate (or wrap) other functions and execute code before and after the wrapped function runs.
Read more >Decorators - Python 3 Patterns, Recipes and Idioms
Function Decorators¶ · aFunction() is called after it has been decorated, we get completely different behavior; the · my_decorator.__call__() method is called ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@cojack Thanks, but I’m aware of this. I’d still rather have the option to apply middleware in the controller since it’ll be much more transparent.
I see usefulness in defining middleware in the module if it’s for all the routes of a controller or something more general. But for things like role specific access control and authentication it’s much more transparent to add it as a decorator in controller imo.
Having to define paths and methods affected in two different places is also something I’d rather avoid.
@silvelo @ThomRick I’m facing a similar dilemma. I want to have transparent route handling and plug authentication and role checking per route in the controller in most cases. Not sure what the advantage is of having this logic separated in another file (Module) and paths redefined in two places.
Something like the UseMiddlewares decorator as below would be great.