python - 列出 Google App Engine 数据存储中的所有实体时出现 AttributeError

标签 python google-app-engine app-engine-ndb

我正在尝试获取我的数据存储中的所有实体,然后使用 HTML 显示它们。我试图从 RequestHandler 内部执行此操作,但我收到错误消息

“AttributeError:类型对象‘Student’没有属性‘all’”

这是我的学生类(class)

class Student(ndb.Model):
   banner_id = ndb.IntegerProperty(required=True)
   name=ndb.StringProperty()
   score=ndb.IntegerProperty()

这是 RequestHandler 代码:

class MainHandler(webapp2.RequestHandler):
def get(self):
    # Create a HTML table
    table = "<html><head><title>Students Server</title></head><body><table><th>name</th><td>score</th>"
    # Now get a list of all students
    sqry = Student.all()
    sqry.order('name')

        # Use the data collected so far to create a table row and add 
        # it to the table
    table += Student.toTableRow(score)
    # Complete the table
    table += "</table>"
    self.response.write(table)
    self.response.write(studentRegistrationPage)

我正在尝试检索所有学生并根据姓名对列表进行排序。从here得到这个想法给出了这样的例子。

# Order alphabetically by last name:
q = Person.all()
q.order('last_name')

# Order by height, tallest to shortest:
q = Person.all()
q.order('-height')

我做错了什么?

最佳答案

您正在尝试执行 db 查询,但您正在使用 ndb

阅读文档 https://developers.google.com/appengine/docs/python/ndb/queries 。另请查看 db/ndb 备忘单 https://docs.google.com/document/d/1AefylbadN456_Z7BZOpZEXDq8cR8LYu7QgI7bt5V0Iw/mobilebasic?pli=1

使用 ndb 查询将是 Person.query()

关于python - 列出 Google App Engine 数据存储中的所有实体时出现 AttributeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23167120/

相关文章:

python - GAE 数据存储查询 ConjunctionNode 错误

python - 祖先索引消耗的存储空间更少吗?大约会消耗多少存储空间?

app-engine-ndb - ndb 计算属性过滤

google-app-engine - 谷歌应用引擎 : Missing required argument 'module[s]'

Python:如何检查一个对象是否是一个模块?

python - Pandas - 反转和分配列名称不起作用

python 结构包(): pack multiple datas in a list or a tuple

java - 如何使用 Google App Engine 的 SQL 到 NoSQL 数据存储重写应用程序

python - GAE 是否支持 django 管理表单

python - 多字符串变量声明python