The source code is below:
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)
Though I can see that classonlymethod can only be called on the class and not on an instance unlike classmethod of python, why do we need such a "restriction"?
Not much on the www regarding classonlymethod and any layman examples appreciated as always.
It is used internally on class-based views' as_view to give a descriptive error message to people who try to call it on an instance.
I'm not sure who first decided it's mandatory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With