2011-08-01 119 views
1

代码:'NoneType' 对象有没有属性 '标题'

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'

我该如何解决这个问题?

+3

每当您在Python错误消息中看到'NoneType',这是因为您已经完成了'无。 '。 –

回答

7

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

+0

而'v'不是因为在数据存储中不存在具有该ID的实体。 –

相关问题