I'm attempting to render a PDF and populate the template with specific data from the object that is being viewed.
I'm using xhtml12pdf / pisa. I've successfully rendered a generic (unpopulated) PDF, however when I add logic to populate a specific object's data, my context is being returned however the pdf is no longer being rendered.
views.py
class GeneratePdf(DetailView):
model = Request
template_name='request_response/response.html'
def get(self, request, *args, **kwargs):
context = super(GeneratePdf,self).get(request,*args,**kwargs)
return context
pdf = render_to_pdf('request_response/response.html',context)
if pdf:
response = HttpResponse(pdf,content_type='application/pdf')
filename = "PrivacyRequest_%s.pdf" %("1234")
content = "inline; filename='%s'" %(filename)
response['Content-Disposition'] = content
return response
return HttpResponse("Not Found")