擅长:python、mysql、java
<p>刚刚意识到,我需要<code>@classmethod</code></p>
<pre><code>class InviteManager():
ALREADY_INVITED_MESSAGE = "You are already on our invite list"
INVITE_MESSAGE = "Thank you! we will be in touch soon"
@classmethod
@missing_input_not_allowed
def invite(cls, email):
try:
db.session.add(Invite(email))
db.session.commit()
except IntegrityError:
return cls.ALREADY_INVITED_MESSAGE
return cls.INVITE_MESSAGE
</code></pre>
<p>你可以看看<a href="https://stackoverflow.com/questions/136097/what-is-the-difference-between-staticmethod-and-classmethod-in-python">here</a></p>