[英]Error in python function pymongo
This is a function that returns an error at the line with post['date']
. 这是一个在
post['date']
的行返回错误的函数。
This is the error: 这是错误:
in get_posts
post['date'] = post['date'].strftime("%A, %B %d %Y at %I:%M%p")
KeyError: 'date'
What does it mean? 这是什么意思?
This is the function: 这是功能:
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
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.