我剛剛開始學習Python,我正在慢慢掌握它,但我遇到了一個問題。不能在同一個Python文件中「定義」兩個數據庫嗎?
我正在嘗試使用Google的App Launcher SDK製作一個包含文章的簡單網站。
現在,一切都工作得很好,當我跟隨谷歌的網站的小指南,但現在我想創建另一個數據庫:
class Articles(db.Model):
title = db.TextProperty()
content = db.StringProperty(multiline=True)
date = db.DateTimeProperty(auto_now_add=True)
沒有錯誤在這裏。 我再嘗試進行查詢,獲取所有信息,並張貼到模板:
class Articles(webapp.RequestHandler):
def get(self):
articles_query = Articles.all().order('-date')
articles = articles_query.fetch(10)
template_values = {'articles': articles}
path = os.path.join(os.path.dirname(__file__), 'articles.html')
self.response.out.write(template.render(path, template_values))
在這裏,我收到了一個錯誤:
line 45, in get
articles_query = Articles.all().order('-date')
AttributeError: type object 'Articles' has no attribute 'all'
我基本上覆制了谷歌的教程,只是更改查詢變量,但它不起作用。
任何想法?
喔,我感到很慚愧..謝謝了很多,我怎麼可能犯這樣的錯誤? – Crembo 2010-11-18 14:33:30
哦,很容易。我每天做3件這樣的事情。 :-) – 2010-11-18 15:29:27