xhtml2pdf django-cms 'sekizai.context_processors.sekizai' or use 'sekizai.context.SekizaiContext'

213 views Asked by At

I am using Django-CMS, but when I try to use the xhtml2pdf example in the views.py I get this error:

TemplateSyntaxError You must enable the 'sekizai.context_processors.sekizai' template context processor or use 'sekizai.context.SekizaiContext' to render your templates.

If I use the example in a Django project without Sekizai no problem, any suggestions?

Thanks.

settings.py

THIRD_PARTY_APPS = (
    ...
    'sekizai',
    ...
)

base.html

{% load cms_tags menu_tags sekizai_tags static i18n %}
...

applications/htmltopdf_app views.py

from django.shortcuts import render
from django.http import HttpResponse
from django.template.loader import get_template
from xhtml2pdf import pisa

# Create your views here.
def render_pdf_view(request):
    template_path = 'htmltopdf_app/cv_to_pdf.html'
    context = {'myvar': 'this is your template context'}

    # Create a Django response object, and specify content_type as pdf
    response = HttpResponse(
        content_type='application/pdf'
    )

    response['Content-Disposition'] = 'attachment; filename="report.pdf"'

    # find the template and render it.
    template = get_template(template_path)
    html = template.render(context)

    # create a pdf
    pisa_status = pisa.CreatePDF(
        html,
        dest=response
    )

    # if error then show some funy view
    if pisa_status.err:
        return HttpResponse('We had some errors <pre>' + html + '</pre>')
    return response
0

There are 0 answers