class Panel(models.Model):
loc = models.IntegerField()
title = models.CharField(max_length=200)
def __unicode__(self):
return self.title
的模板與面板實例從視圖提供:
def index(request):
return render_to_response('application/index.html',
{"DEBUG": True,
"panels": Panel.objects.all() },
context_instance=RequestContext(request))
模板嘗試如下訪問特定模型實例:
{% with panel = panels[1] %}
...presentation logic....
{% endwith %}
目前此結果爲
TemplateS yntaxError在/ applicatino/ u'with」預計將有至少一個變量賦值
杜pstate http://stackoverflow.com/questions/4063515/django-template-question-accessing-a-list – Manfre