concept_name
和reka_1
- >模型中列的名称提前感谢您的回答!
我收到的错误消息:
/ concepts / chapter1 /上的TemplateSyntaxError无法解析余数:'%for concept in concept_chapter_1%'来自'%for concept in concept_chapter_1%'
views.朋友
def chapter_1(request):
concept_chapter_1 = Concept.objects.values('concept_name', 'reka_1')
return render(request, 'concepts/chapter_1.html',{'concept_chapter_1':concept_chapter_1})
URLs.朋友
urlpatterns = [.... url(r'^ chapter1 / $',views.chapter_1,name ='chapter1'),url(r'^ chapter2 / $',views.chapter_2,name ='chapter2'),
Hmtk
{{% for concept in concept_chapter_1 %}}
<tr>
<td>{{ concept.concept_name }}</td>
<td>{{ concept.reka_1 }}</td>
</tr>
{% endfor %}
它让我感到惊讶,但找到了该计划的可能解决方案。我之前的代码中存在多个问题。我不敢解释为什么以及如何工作,它只是经过大量的尝试和修改后才能工作,我希望它可以帮助别人
新的和工作版本从数据到html打印两列
views.朋友
def chapter_1(request):
concept_chapter_1 = Concept.objects.values('concept_name', 'reka_1')
concept = {"concepts_chapter1": concept_chapter_1}
return render(request, 'concepts/chapter_1.html', context=concept)
HTML
{% if concepts_chapter1 %}
<table>
<thead>
<th>Concept</th>
<th>Records</th>
</thead>
{% for randomobject in concepts_chapter1 %}
<tr>
<td>{{ randomobject.concept_name }}</td>
<td>{{ randomobject.reka_1 }}</td>
</tr>
{% endfor %}
</table>
{% endif %}