I have seen this in one the facebook.py User file.
class User(db.Model):
username = db.StringProperty(required=True)
password = db.StringProperty(required=True)
@classmethod
def get_by_email(cls, email):
return cls.query(cls.email == email).get()
What does cls mean? if you put self, it is referring to the User class normally. But what’s cls refer to?
Thanks in advance.
The name does not matter, but applying
classmethoddecorator makes the method a class method. In such case the first argument is a class, not an instance.Please take a look at the comparison of instance, class and static methods using the following code:
By convention, when you are referring to the same instance, you name it
self. When you are referring to its class, you name itcls. That is only a convention, but it is better to follow it for consistency.