'NoneType'对象没有属性'title'

时间:2011-08-01 13:11:31

标签: python google-app-engine

代码:

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 个答案:

答案 0 :(得分:7)

函数form.get_by_id(int(id))已返回给定None的{​​{1}},因此id没有属性v,因为它是title