I'm using Django 1.8 and I want to export an HTML document to PDF, for this I use wkhtmltopdf, in addition to other libraries I had to import the following and the file view.py was like this:
from django.views.generic import DetailView
from wkhtmltopdf.views import PDFTemplateResponse
class MyPDFView(DetailView):
model1 = Contrato
model2 = Servicio_Contratado
template = 'acuerdos.html'
context = {'titulo': 'CubanCloud'}
def get(self, request, *args, **kwargs):
self.context['entry'] = self.get_object()
response = PDFTemplateResponse(request=request,
template=self.template,
filename="Contrato CubanCloud.pdf",
context=self.context,
footer_template="footer.html",
show_content_in_browser=True,
cmd_options={'margin-top': 15,
'margin-bottom': 20,
'default-header': True,
'header-left':Cubancloud',
'footer-line': True,
},
)
return response
The url was like this:
url(r'^/pdf$', views.MyPDFView.as_view(), name='pagina_detalle'),
I call the operation using a link in the template, which is as follows:
<a href="{% url "pagina_detalle" %}"> Generar PDF de</a>
When I click on the link I get the following error message:
ImproperlyConfigured at /cubancloud/pdf
MyPDFView is missing a QuerySet. Define MyPDFView.model, MyPDFView.queryset, or override MyPDFView.get_queryset().