내 데이터 저장소의 모든 항목을 가져온 다음 HTML을 사용하여 표시하려고합니다. 내부에서 이것을 시도하고 RequestHandler
있지만 오류 메시지가 나타납니다.
"AttributeError: type object 'Student' has no attribute 'all'"
이것은 내 Student
수업입니다
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)
모든 학생을 검색하고 이름을 기준으로 목록을 정렬하려고합니다. 여기 에서 이와 같은 예가 주어진 아이디어를 얻었습니다 .
# 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()
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다