I want to generate a PDf of a django template / view; that uses templatetags etc.
From django-wkhtmltopdf's documentation:
from django.conf.urls.defaults import url, patterns
from wkhtmltopdf.views import PDFTemplateView
urlpatterns = patterns('',
url(r'^pdf/$', PDFTemplateView.as_view(template_name='my_template.html',
filename='my_pdf.pdf'), name='pdf'),
)
Or they say in your own view:
from wkhtmltopdf.views import PDFTemplateView
class MyPDF(PDFTemplateView):
filename = 'my_pdf.pdf'
template_name = 'my_template.html'
cmd_options = {
'margin-top': 3,
}
If this was my view:
def download_report(request):
vends = Vends.objects.all()
return render(request, 'report_template.html', {'vends':vends})
How would I generate a report of this VIEW as its rendered? Not just the template, because that would be useless?
You can use PDFTemplateRespone instead of render_to_response.
from wkhtmltopdf.views import PDFTemplateResponse
Then you can do something like this:
def pdf(request, pk):
context = RequestContext(request)
template = 'test.html'
context = {
'variable1': variable1,
'variable1': variable1,
'variable1': variable1,
'variable1': variable1
}
return PDFTemplateResponse(request=request, cmd_options={'disable-javascript':True}, template=template, context=context)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With