微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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 举报,一经查实,本站将立刻删除。