我目前使用基于类的视图实现了库贷款模板。实施可能是我们以前见过的:
在urls.py
:
#PK is the member ID
url(r'^library/generate_loan_slip/(?P<pk>(\d+))/(?P<loan>(\d+))/'
,LoanSlipDetailView.as_view()
, name='library_app_generate_loan_slip'),
在views.py
:
class LoanSlipDetailView(DetailView):
model = LibraryMember
loan = None
template_name = 'loan-slip.html'
def get_context_data(self, **kwargs):
context['loan'] = self.loan
context['member'] = member
return context
def get_object(self):
member = self.model.objects.get(pk=self.kwargs['pk'])
self.loan = LibraryLoan.objects.get(pk=self.kwargs['loan'], for_member=member)
return member
在HTML loan-slip.html
中,html包含{{}}
中的所有必需变量,并使用{% if %} ... {% else %} ... {% endif %}
和{% for ... %} ... {% endfor %}
进行控制。
现在,我希望响应生成PDF视图。到目前为止,我已经检查了reportlab
并且他们为基于函数的视图实现了它。但是,是否有基于类的视图的实现?
答案 0 :(得分:0)
您可以覆盖DetailView的get方法并在那里编写reportlab逻辑。