Google app engine 无法使用新版本从数据库打印数据

Google app engine 无法使用新版本从数据库打印数据,google-app-engine,web.py,Google App Engine,Web.py,我使用的是web.py的最新版本 我正在尝试将数据从数据库打印到网页。 我使用的代码如下 import web from google.appengine.ext import db from models import * urls = ( '/', 'index', ) render = web.template.render('templates', base='base') class index: def GET(self): votes = db.G

我使用的是web.py的最新版本

我正在尝试将数据从数据库打印到网页。 我使用的代码如下

import web
from google.appengine.ext import db
from models import *

urls = (
  '/', 'index',
)

render = web.template.render('templates', base='base')

class index:
    def GET(self):
        votes = db.GqlQuery("SELECT * FROM votes")
        return render.index(votes)

app = web.application(urls, globals())
main = app.cgirun()
$def with(votes)


$for vote in votes:
    <li>$vote.status</li>
模板如下所示

import web
from google.appengine.ext import db
from models import *

urls = (
  '/', 'index',
)

render = web.template.render('templates', base='base')

class index:
    def GET(self):
        votes = db.GqlQuery("SELECT * FROM votes")
        return render.index(votes)

app = web.application(urls, globals())
main = app.cgirun()
$def with(votes)


$for vote in votes:
    <li>$vote.status</li>
$def带(投票)
美元用于投票:
  • $vote.status
  • 当我运行它时,我得到了这个

    [<models.votes object at 0x0000000004525F28>]
    
    []
    
    这是一个新版本的错误,因为在以前的版本它的工作


    我忘了说我正在按照规定编译模板。

    我不使用web.py;但它可能不支持模板中的生成器/可重用项。首先尝试通过将行更改为以下方式获取结果:

    votes = db.GqlQuery("SELECT * FROM votes").fetch(100)
    

    它在我的机器上运行,使用以下代码运行最新版本:

    main.py

    import web
    from google.appengine.ext import db
    
    class Votes(db.Model):
      status = db.StringProperty()
    
    urls = (
      '/', 'Index',
    )
    
    render = web.template.render('templates', base='base')
    
    class Index:
        def GET(self):
            vote = Votes()
            vote.status ="foo"
            vote.put()
    
            votes = db.GqlQuery("SELECT * FROM Votes")
            return render.index(votes)
    
    app = web.application(urls, globals())
    main = app.cgirun()
    
    模板/index.html

    $def with(votes)
    
    $for vote in votes:
        <li>$vote.status</li>
    
    $def带(投票)
    美元用于投票:
    
  • $vote.status
  • 模板/base.html

    $def with (content)
    <html>
        <head>
        </head>
        <body>
            $:content
        </body>
    </html>
    
    $def带(内容)
    $:内容
    
    结果是:


    您确定没有使用
    投票
    模型类隐藏
    投票
    查询结果吗?尝试将您的班级定义从
    投票
    重命名为
    投票
    。是的,我确定。我将我的类重命名为
    vows
    ,并且得到了相同的输出。使用
    vows=vows.all()
    解决问题?我应该在哪里使用它?将
    vows=db.GqlQuery(“SELECT*FROM vows”)
    替换为
    vows=vows.all()
    并尝试一下。我也在使用web.py的最新版本,但我没有任何问题,但我倾向于使用类模型方法,而不是GqlQuery类。