我有一个由通用列表视图呈现的模板。我想在表格中每行数据的前面提供一个下载链接。下载链接将创建相应行数据的PDF文件。请告诉我如何为此编写代码?
Views.py
class BookingConfirmationListView(LoginRequiredMixin, generic.ListView):
model = container_booking
template_name = 'home/booking_confirmation_detail.html'
context_object_name = 'all_container'
def get_queryset(self):
return container_booking.objects.all()
模板看起来像
<table class="table-striped table-hover table-bordered" width="100%">
<tr>
<th>Date</th>
<th>Source</th>
<th>Destination</th>
<th>Container</th>
<th>Commodity</th>
<th>Agreed Rate</th>
<th>Edit</th>
<th>Delete</th>
<th>Status</th>
</tr>
{% for item in all_container %}
<tr>
<td>{{ item.date }} </td>
<td>{{ item.place_of_reciept }} </td>
<td>{{ item.final_place_of_destination }} </td>
<td>{{ item.equipment_type }}{{ item.quantity }} </td>
<td>{{ item.commodity }} </td>
<td>{{ item.agreed_rate }} </td>
<td><a href="{% url 'home:cont_bk-update' item.id %}" ><i class="fas
fa-edit"></i></a></td>
<td><a href="{% url 'home:cont_bk-delete' item.id %}" ><i class="fas
fa-trash"></i></a></td>
<td>{{ item.approved }}</td>
</tr>
{% endfor %}
</table>
urls.py
url(r'^cont_bkdetail$', views.BookingConfirmationListView.as_view(),
name='cont_bk-detail'),
url(r'^cont_bk/(?P<pk>[0-9]+)/$',
views.BookingConfirmationUpdate.as_view(), name='cont_bk-update'),
url(r'^cont_bk/(?P<pk>[0-9]+)/delete/$',
views.BookingConfirmationDelete.as_view(), name='cont_bk-delete'),
我希望每当我单击下载时,都会生成该行的PDF文件。