NoneType' 对象没有 'title' 属性

1 投票
1 回答
2107 浏览
提问于 2025-04-16 22:39

代码:

class trafikformu(db.Model):

    title = db.StringProperty()

class QueryHandler(webapp.RequestHandler):
    def get(self,id):
        v = form.get_by_id(int(id))
        self.response.out.write(v.title) # AttributeError

这一行 self.response.out.write(v.title) 出现了这个错误:'NoneType' object has no attribute 'title'

我该如何解决这个问题呢?

1 个回答

7

这个函数 form.get_by_id(int(id)) 对于给定的 id 返回了 None,所以 v 没有 title 这个属性,因为它是 None

撰写回答