python函数pymongo中出现错误

python函数pymongo中出现错误,python,mongodb,mongodb-query,pymongo,keyerror,Python,Mongodb,Mongodb Query,Pymongo,Keyerror,这是一个函数,在带有post['date']的行中返回错误 这就是错误: in get_posts post['date'] = post['date'].strftime("%A, %B %d %Y at %I:%M%p") KeyError: 'date' 这是什么意思 这就是功能: def get_posts(self, num_posts): cursor = self.posts.find({},{}).limit(num_posts) # Using an emp

这是一个函数,在带有
post['date']
的行中返回错误

这就是错误:

in get_posts
    post['date'] = post['date'].strftime("%A, %B %d %Y at %I:%M%p")
KeyError: 'date'
这是什么意思

这就是功能:

def get_posts(self, num_posts):

    cursor = self.posts.find({},{}).limit(num_posts) # Using an empty itable for a placeholder so blog compiles before you make your changes
    # XXX HW 3.2 Work here to get the posts
    l = []

    for post in cursor:
        print post          
        post['date'] = post['date'].strftime("%A, %B %d %Y at %I:%M%p")
        if 'tags' not in post:
            post['tags'] = [] # fill it in if its not there already
        if 'comments' not in post:
            post['comments'] = []

        l.append({'title':post['title'], 'body':post['body'], 'post_date':post['date'],
                  'permalink':post['permalink'],
                  'tags':post['tags'],
                  'author':post['author'],
                  'comments':post['comments']})

    return l

KeyError:'date'
表示
post
没有属性
date

KeyError:'date'
表示
post
没有属性
date

可能重复的