As mentioned by other people, the best way to do this is to create a template and then convert the result using one of the many libraries to PDF. This method gives you the usual level of control over your templates, for example using tags.
ReportLab/Pisa, , , , CSS2 .
wkhtmltopdf, WebKit. , -, , , webkit, CSS3, WebKit.
django-wkhtmltopdf, render_to_pdf Django render_to_response.
: .
Update
CBV, ( , ) .
. quickstart docs , . , PDFTemplateView , .
:
from django.shortcuts import render_to_response
from wkhtmltopdf import render_to_pdf
def pdf(request):
context.update({'objects': ModelA.objects.filter(p_id=100)})
kwargs = {}
if request.GET and request.GET.get('as', '') == 'html':
render_to = render_to_response
else:
render_to = render_to_pdf
kwargs.update(dict(
filename='model-a.pdf',
margin_top=0,
margin_right=0,
margin_bottom=0,
margin_left=0))
return render_to('pdf.html', context, **kwargs)
? as = html , . , .
, objects , , . PDF , - PDF , , , .
, PDF , render_to_pdf kwargs.