简体   繁体   English

如何使用django @lazy decorator?

[英]How do I use django @lazy decorator?

First try with the django.utils.functional.lazy decorator. 首先尝试使用django.utils.functional.lazy装饰器。 My function returns two lists, so I'm decorating it with @lazy(list, list). 我的函数返回两个列表,所以我用@lazy(list,list)装饰它。 It's a plain jane function, not a method/property on a class. 它是简单的简写函数,不是类的方法/属性。

I'm getting a "' proxy ' object is not callable" when I try to call the resulting decorated function. 尝试调用生成的修饰函数时,出现“无法调用' proxy '对象”的情况。

I don't think you can use Django's lazy as decorator. 我认为您不能使用Django的lazy作为装饰器。 You can use it as a function call: 您可以将其用作函数调用:

lazy_function = lazy(f, type)

where f is the function you need to make lazy and type is the expected data type. 其中f是您需要延迟的函数, type是预期的数据类型。

Also how do you return the two lists? 还如何返回两个列表? Like: 喜欢:

def a():
    return [], []

If yes, then technically you are returning a tuple hence you should use lazy as: 如果是,那么从技术上讲,您将返回一个元组,因此应将lazy用作:

lazy_f = lazy(f, tuple)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM