相关疑难解决方法(0)

Django 的 classonly 方法有什么用?

源代码如下:

class classonlymethod(classmethod):
    def __get__(self, instance, owner):
        if instance is not None:
            raise AttributeError("This method is available only on the view class.")
        return super(classonlymethod, self).__get__(instance, owner)
Run Code Online (Sandbox Code Playgroud)

虽然我可以看到 classonlymethod 只能在类上调用,而不能在实例上调用,这与 python 的 classmethod 不同,为什么我们需要这样的“限制”?

www 上关于 classonlymethod 的内容不多,并且一如既往地赞赏任何外行示例。

python django

3
推荐指数
1
解决办法
1368
查看次数

标签 统计

django ×1

python ×1