xhtml2pdf django-cms 'sekizai.context_processors.sekizai' 或使用 'sekizai.context.SekizaiContext'

问题描述

我正在使用 Django-CMS,但是当我尝试在 views.py 中使用 xhtml2pdf 示例时,我收到此错误

模板语法错误 您必须启用“sekizai.context_processors.sekizai”模板上下文处理器或使用“sekizai.context.SekizaiContext”来呈现您的模板。

如果我在没有 Sekizai 的 Django 项目中使用该示例没问题,有什么建议吗?

谢谢。

settings.py

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

base.html

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

applications/htmltopdf_app 视图.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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)