2014-04-09 40 views
0

我是django的新手,到目前爲止都很難學習它。儘管有很多文件,但我不能把它們放在一起。現在我停留在把一本字典的表...(是的,我去了低谷教程)django中的表字典

的Django 1.6和Python 2.7版

觀點:

def panel(request): 
adlist = {} 
adlist['title'] = 'haas','paas' 
adlist['price'] = 12,50 
adlist['bid'] = 50,0 
adlist['seen'] = 23,11 
context = {'adlist' : adlist} 
return render(request, 'panel.html', context)enter code here 

模板(我試過很多的變化):

<table class="zebra"> 
<caption>Panel.</caption> 
    <thead> 
     <tr> 
      <th>title</th> 
      <th>price</th> 
      <th>bid</th> 
      <th>seen</th> 
     </tr> 
    </thead> 
    <tbody> 
    {% for ad in adlist %} 
     <tr> 

      <td>{{ ad.title }}</td> 
      <td>{{ ad.price}}</td> 
      <td>{{ ad.bid}}</td> 
      <td>{{ ad.seen}}</td> 

     </tr> 
    {% endfor %} 
    </tbody> 
</table> 
+0

可能重複的[Django模板表字典](http://stackoverflow.com/questions/10040037/dictionary-as-table-in-django-模板) – Andy

回答

2

你需要做的廣告,而不是一本字典的列表,例如:

def panel(request): 
    adlist = [{'title': 'haas', 'price': 12.50, 'bid': 50.0, 'seen': 23.11}] 
    return render(request, 'panel.html', {'adlist' : adlist}) 
+0

謝謝,它現在正在工作。 <3 – Peter