2012-05-03 90 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「理智」... –