1
Django的版本:1.11.3Django的sqlite的內容
,我希望顯示在PDF我已經存儲在SQLite數據庫的數據。我使用easy-pdf。我不知道如何在不使用render()的情況下解析數據。我怎麼用get_context_data()來做到這一點。有什麼建議麼?
這工作:
def test(request):
all_organizations = Organization.objects.all()
all_tickets = Ticket.objects.all()
context = {'all_organizations': all_organizations, 'all_tickets': all_tickets}
return render(request, 'test/docs/examples/theme/test.html', context)
不知道如何解析all_organizations和all_tickets用於易於PDF:
class HelloPDFView(PDFTemplateView):
all_organizations = Organization.objects.all()
all_tickets = Ticket.objects.all()
context = {'all_organizations': all_organizations, 'all_tickets': all_tickets}
template_name = "test/docs/examples/theme/hello.html"
def get_context_data(self, **kwargs):
return super(HelloPDFView, self).get_context_data(
pagesize="A4",
title="Test",
**kwargs
)
不起作用。這是否返回上下文?當它已經返回超級? –
抱歉嘗試編輯ans – Exprator
OMG。有用!你太棒了!非常感謝! –