这是我的代码长这个样子
class InviteManager():
ALREADY_INVITED_MESSAGE = "You are already on our invite list"
INVITE_MESSAGE = "Thank you! we will be in touch soon"
@staticmethod
@missing_input_not_allowed
def invite(email):
try:
db.session.add(Invite(email))
db.session.commit()
except IntegrityError:
return ALREADY_INVITED_MESSAGE
return INVITE_MESSAGE
当我运行我的测试时,我看到
NameError: global name 'INVITE_MESSAGE' is not defined
如何在@staticmethod
内部访问INVITE_MESSAGE
?
staticmethod
访问class variable
?是否有必要使用classmethod
?如果它们都可以访问类变量,那么classmethod
和staticmethod
之间的不同用例是什么? - JavaSa