2016-09-29 104 views
0

我如何在我的python文件中訪問{{c.key().id()}}?它正確地打印出我的HTML中正確的ID。當我嘗試從請求中獲取ID時,出現錯誤UndefinedError: 'None' has no attribute 'key',但是如果我將id設置爲 id=5222955109842944這樣的工作。UndefinedError:'None'沒有屬性'key'

當我用id= Comment.key().id()我得到

id = Comment.key.id 
AttributeError: 'function' object has no attribute 'id'or id= Comment.key.id 

當我試圖id = Comment.key()我在Python文件得到

id = Comment.key() 
TypeError: unbound method key() must be called with Comment instance as first argument (got nothing instead) 

我有這個

 #id=5222955109842944 
     id = self.request.get('id') 



     name = 'testname1' 
     key = db.Key.from_path('Comment', id) 

     comments = db.get(key) 

當我試圖讓來自請求的ID我收到錯誤UndefinedError: 'None' has no attribute 'key'

這是我的html文件:

comment id{{c.key().id()}} 


    <a href="/blog/editcomment?id={{c.key().id()}}">Edit Comment</a><br><br> 

回答

2

self.request.get('id')是一個字符串。你需要把它變成一個int

int(self.request.get('id'))

+0

@約翰如果這個答案幫助你,你應該考慮接受它(點擊旁邊的答案標記)來指示其他讀者,這實際上解決了你問題。 – idjaw

+0

對不起,延遲了回覆。直到今天,我都不知道這個複選標記。我一直在點擊沒有用的向上箭頭,因爲我沒有超過15的聲望。再次感謝你的幫助。 – John