1
post['date']
과 함께 줄에 오류를 반환하는 함수입니다. python 함수의 오류 pymongo
이
오류입니다 :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
[나는 파이썬에서 키 오류가 나옵니다]의 가능한 복제본 (http://stackoverflow.com/questions/10116518/im-getting-key-error-in-python) – fzzle