2👍
Not exactly. The decorator syntax:
@register.filter
def a():
pass
is syntactic sugar for:
def a():
pass
a = register.filter(a)
So register.filter
in this case will be called with the first positional argument, ‘name’ being your function. The django register.filter function handles that usage however and returns the right thing even if the filter is sent as the first argument (see the if callable(name)
branch)
It’s more common to make decorators that can take multiple arguments do so with the function to be decorated being the first positional argument (or alternately being function factories/closures), but I have a feeling the reason django did it this way was for backwards-compatibility. Actually I vaguely remember it not being a decorator in the past, and then becoming a decorator in a later django version.
0👍
No. Simple decorators take the function they decorate as a parameter, and return a new function.
a = register.filter(a)
- [Answered ]-Why doesn't django like my dictionary?
- [Answered ]-How does the admin app work without collectstatic?
- [Answered ]-How to pass template variables to javascript