2012-05-03 91 views
0

我的意见,采取从列表字典值:如何使用Django模板

post_details = Post.objects.all() 
    for each in post_details: 
     post_like_list=PostLikes.objects.filter(post = each) 
     pl=len(post_like_list) 
     dict1={"post":each} 
     dict2={"how many likes":pl} 
     list.append([dict1,dict2]) 
    print list 

我的目录= [[{ '后':住宿},{ '有多少喜欢':0}],[{”后':选举},{'多少个喜欢':0}],[{'后':},{'多少个喜欢':3}],[{'''''','' :1}]]

通过使用django模板,我怎样才能从列表中的字典中获得'后'和'多少喜欢'?

回答

4

如果使结构理智......

list.append({"post": each, "how many likes": pl}) 

,那么你会发现,你可以使用{% for %}遍历列表,然后访问使用正常访问方法的类型的字典。

+1

+1“理智”... –