以 @ 开头的 python 行
可能的重复:
了解 Python 装饰器
我正在阅读 django 应用程序源代码,在其中我找到了
@login_required
def activities(request = None,\
project_id = 0,\
task_id = 0,\
...
以 What does the line that start with @ 意思是?
Possible Duplicate:
Understanding Python decorators
I was reading a django app source code where I find this
@login_required
def activities(request = None,\
project_id = 0,\
task_id = 0,\
...
What does the line that start with @ mean?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
它是一个装饰器,是 Python 中一种特殊类型的函数(在某些情况下是类),可以修改另一个函数的行为。请参阅本文。
实际上只是一个特殊的语法
It's a decorator, which is a special type of function (or class, in some cases) in Python that modifies another function's behavior. See this article.
is really just a special syntax for
请查看Python 装饰器解释。它有一个令人惊奇的答案,可以解释一切。
Please check out Python Decorators Explained. It has an amazing answer that will explain everything.
它是一个装饰器。它是一种合成糖,用于:
It is a decorator. It's a syntatic sugar for:
这是一个装饰器。它所做的基本上就是包装函数。它与此代码等效:
它用于检查函数参数(在本例中为 request.session )、修改参数(它可能会为函数提供除传递之外的其他参数),也许还有其他一些东西。
It's a decorator. What it does is basically wrap the function. It is equivalent with this code:
It is used for checking function arguments (in this case
request.session
), modifying arguments (it may give the function other arguments than it passes), and maybe some other stuff.