【问题标题】:django-easy-pdf displays no contentdjango-easy-pdf 不显示内容
【发布时间】:2018-08-15 02:26:53
【问题描述】:

我想使用 django-easy-pdf 渲染一个带有 Django 的 pdf 文件。我关注了these instructions,但我得到了一个空的pdf。

这是我的html:

{% extends "easy_pdf/base.html" %}

{% block extra_style %}
{% endblock %}

<% block content %>
  <div id="summary-block">
    <p>Here goes that square with data.</p>
  </div>
  <div id="declarations-block">
    <p>Here goes the Main content.</p>
  </div>
  <div id="data-block">
    <p>Here goes all the data from the contract.</p>
  </div>
  <div id="clause-block">
    <p>Here goes the Clause content.</p>
  </div>
  <div id="signatures-block">
    <p>Here goes the signatures content.</p>
  </div>
<% endblock %>

这是我的views.py

from django.shortcuts import render
from django.conf import settings
from easy_pdf.views import PDFTemplateView

# Create your views here.
class ContractPDFView(PDFTemplateView):
    template_name = 'contract.html'

    base_url = 'file://' + settings.TEMPLATES_DIR
    download_filename = 'contract.pdf'

    def get_context_data(self, **kwargs):
        return super(ContractPDFView, self).get_context_data(pagesize='letter', title='Contract', **kwargs)

我不知道我错过了什么。

【问题讨论】:

    标签: python django pdf pdf-generation


    【解决方案1】:

    虽然答案有点晚了 - 你的错误是你在模板中混合了 和 {}。

    代替

    <% block content %><% endblock content %> 
    

    应该是

    {% block content %}{% endblock content %}.
    

    【讨论】:

      猜你喜欢
      • 2014-05-02
      • 2020-02-20
      • 1970-01-01
      • 2015-10-18
      • 2019-09-24
      • 2016-08-30
      • 1970-01-01
      • 2017-01-07
      • 2017-09-04
      相关资源
      最近更新 更多