은 내 템플릿에 같은 코드를 많이 가지고 : 위의 사람들처럼 만들어Python : Jinja2를 사용하여 DRY 방식으로 어떻게 구현할 수 있습니까?
<h2>Owners of old cars</h2>
<table id="hor-minimalist-b" summary="Old Cars">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Age</th>
<th scope="col">Address</th>
</tr>
</thead>
<tbody>
{% for result in old_cars %}
<tr>
<td>{{result.name}}</td>
<td>{{result.age}}</td>
<td>{{result.address}}</td>
</tr>
{% endfor %}
</tbody>
</table>
<h2>Owners of Ford cars</h2>
<table id="hor-minimalist-b" summary="Old Cars">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Age</th>
<th scope="col">Address</th>
</tr>
</thead>
<tbody>
{% for result in ford_cars %}
<tr>
<td>{{result.name}}</td>
<td>{{result.age}}</td>
<td>{{result.address}}</td>
</tr>
{% endfor %}
</tbody>
</table>
이있을 것입니다 훨씬 더 많은 테이블을. 보시다시피 중복 코드가 많이 있습니다. 어쨌든이 작업을 수행 할 때마다 테이블을 만들 때마다 많은 코드를 반복하지 않습니까? 감사.
UPDATE
나는 테이블라는 새로운 객체를 생성하고, 그 결과와 그것에 대응하는 H2 타이틀을 추가하는 방법에 대해 생각하고 있어요. 그런 다음 템플릿이라는 테이블에 전달할 수있는 테이블 개체의 목록을 만들 수 있습니다. 그런 다음 템플릿을 반복 할 수 있습니다. 테이블
<table id="hor-minimalist-b" summary="Old Cars">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Age</th>
<th scope="col">Address</th>
</tr>
</thead>
<tbody>
의 머리글과 바닥 글에 대한
예. 감사. – Ambrosio