我想使用 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)
我不知道自己在想什么。
答案 0 :(得分:2)
尽管答案有点晚-您的错误是您在模板中混合了<>和{}。
代替
<% block content %><% endblock content %>
应该是
{% block content %}{% endblock content %}.