easypd中的Django sqlite含量

2024-05-14 09:42:27 发布

您现在位置:Python中文网/ 问答频道 /正文

Django版本:1.11.3

我已将数据存储在sqlite数据库中,正如我希望以pdf格式显示的那样。我使用简易pdf。我不知道如何在不使用render()的情况下解析数据。如何使用get\u context\u 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)

不知道如何解析easy pdf中使用的所有\u组织和所有\u票证:

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
    )

Tags: 数据testdatagetobjectspdfrequestdef
1条回答
网友
1楼 · 发布于 2024-05-14 09:42:27
def get_context_data(self, **kwargs):
    context = super(HelloPDFView, self).get_context_data(**kwargs)
    context['all_organizations'] = Organization.objects.all() 
    context['all_tickets'] = Ticket.objects.all()
    context['pagesize']="A4"
    context['title']= 'Test'
    return context

试试这个,在模板中,您可以使用pagesize、title和all等关键字名称访问数据

相关问题 更多 >

    热门问题