To improve learning of decorators I've decided to find real-life examples of decorators in django framework.
To The Point
To be more precise in our adventure through decorators I decided to look for the most used python frameworks/libraries and find decorators that may be useful.
In Django documentation you can find View Decorators which explains view decorators. In the source-code of django you can find those decorator packages/modules:
-
-
require_http_methods
is a http-method decorator that uses @wraps - from which we learn that using@wraps
at decorator inner-function prevents problem with passing__docs__
and__name__
of decorated function. -
require_GET
is a derivation ofrequire_http_methods
which includes onlyGET
method as a parameter to that function. - also it changes__doc__
of the function to have different docs than inrequire_http_methods
- for more readability.
-
Acknowledgements
Auto-promotion
Related links
- GitHub - django/django: The Web framework for perfectionists with deadlines.
- View decorators | Django documentation | Django
- GitHub - vinta/awesome-python: A curated list of awesome Python frameworks, libraries, software and resources
- GitHub - uralbash/awesome-pyramid: A curated list of awesome Pyramid apps, projects and resources.
- 10.2. functools — Higher-order functions and operations on callable objects — Python 3.6.5rc1 documentation
- 10.2. functools — Higher-order functions and operations on callable objects — Python 3.6.5rc1 documentation
Thanks!
That's it :) Comment, share or don't - up to you.
Any suggestions what I should blog about? Post me a comment in the box below or poke me at Twitter: @anselmos88.
See you in the next episode! Cheers!
Comments
comments powered by Disqus