0
我目前有一个使用基于类的视图实现的图书馆借阅模板。实现是可能的东西,我们以前见过:使用基于Django类的视图生成PDF
在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
,并且他们实现了基于功能的视图。但是,基于类的视图有没有实现?
hello!你能给我更多的基础知识吗?只是一些代码片段让我去。我相信这对我来说不仅仅是有用,因为它是一个非常常见的用例 – bryansis2010