例一AttributeError的:「瓶」對象有沒有屬性「模板」
考慮以下幾點:
import bottle
import pymongo
application = bottle.Bottle()
@application.route('/')
def index():
cursor = [ mongodb query here ]
return application.template('page1',{'dbresult':cursor['content']})
假設MongoDB的查詢是正確的,並且應用程序調用content
值cursor
正確,並將其傳遞到格式正確的模板。
我在日誌中獲得的錯誤是用能夠使用的template()
方法如做:如果我改變了相應的分配和調用
AttributeError: 'Bottle' object has no attribute 'template'
例二
:
application = bottle
application.template
的錯誤是:
TypeError: 'module' object is not callable
例三
如果我改變了相應的分配和調用:
application = bottle
@application.route('/')
@application.view('page1.tpl')
return {'dbresult':cursor['content']}
的錯誤是:
TypeError: 'module' object is not callable
問題
使用template()
方法獲得Example One
的正確方法是什麼?