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

hic*_*cay 1 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
Run Code Online (Sandbox Code Playgroud)

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

我怎么解决这个问题?

Sve*_*ach 7

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