我正在使用 Python 和 GAE,我正在尝试创建一个字典,其中键是用户 ID,值是“学生”对象。但是,我的字典的值是 None 而不是学生对象。
{'60': , '59': }
如果有人能指出我正确的方向,我将不胜感激!
学生.py
class Student:
def __init__(self, name, s_id, rew = {}):
self.name = name.strip()
self.rewards = {"Creativity": 0, "Helping Others":0, "Participation":0, "Insight":0}
self.totalRewardPoints = 0
self.s_id = s_id
Main.py(我只包含了相关代码)
class PageHandler(webapp2.RequestHandler):
def write(self, *a, **kw):
self.response.out.write(*a, **kw)
def initialize(self, *a, **kw):
webapp2.RequestHandler.initialize(self, *a, **kw)
def create_students(self):
user = db.GqlQuery("SELECT * FROM User WHERE position='student'")
for u in user:
temp_id = str(u.key().id())
self.students[temp_id] = student.Student(u.name, temp_id)
class MainPage(PageHandler):
students = {}
def get(self):
user = db.GqlQuery("SELECT * FROM User WHERE position='student'")
for u in user:
temp_id = str(u.key().id())
self.students[temp_id] = student.Student(u.name, temp_id)
self.write(self.students)
app = webapp2.WSGIApplication([('/', MainPage)], debug=True)