1
我真的很新編程...我設置了一個類來爲Google的User API用戶對象提供支持信息。我使用db.model將此信息存儲在數據存儲中。GAE - 獲取需要類實例的TypeError傳遞給類自己的方法
當我打電話使用此代碼我USER_INFO類的okstatus方法:
elif user_info.okstatus(user):
self.response.out.write("user allowed")
我得到這個錯誤:
unbound method okstatus() must be called with user_info instance
as first argument (got User instance instead)
這是我USER_INFO類。
class user_info:
def auth_ctrlr(self, user):
if self.status(user) == status_allowed:
return ("<a href=\"%s\">Sign Out</a>)" %
(users.create_login_url("/")))
else:
return ("<a href=\"%s\">Sign In or Get an Account</a>)" %
(users.create_logout_url("/")))
def status(self, user):
match = sub_user.gql(qu_by_user_id, user.user_id)
return match.string_status
def group(self, user):
match = sub_user.gql(qu_by_user_id, user.user_id)
grp = group_names.gql(qu_by_user_id, match.groupID)
return grp
def okstatus(self, user):
match = self.status(user)
if match == status_allowed:
return True
我的理解是,方法調用參數中的參數「self」將其描述爲類的子類。我嘗試了所有我能想到的,並且無法在網上找到任何相關信息。有人可以告訴我我做錯了什麼嗎?
感謝
你是非常正確的。感謝您幫助我真正瞭解情況。我會接受你的建議並使其功能化。 – 2010-03-18 02:40:32