我处于调试状态,我想使用 PrinceXML 将 HTML 页面呈现为 PDF。
在我的主要 HTML 中,我有:
{% extends "base.html" %}
{% load staticfiles %}
{% load url from future %}
{% block title %}Title{% endblock %}
{% block style %}
{% include "style.html" %}
<link rel="stylesheet" type="text/css" href="{% static "more.style.css" %}"/>
{% endblock %}
{% block branding %}<a class='brand' rel="nofollow" href="{% url 'url' %}">Brand</a>{% endblock %}
{% block userlinks %}
{% if user.is_authenticated %}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
{{ user }}
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a href="{% url 'generate-pdf' %}">Get the doc in pdf</a></li>
<li><a href="{% url 'dashboard.views.index' %}">Home</a></li>
<li><a href="{% url 'logout' %}">Logout</a></li>
</ul>
</li>
{% endif %}
{% endblock %}
我的 style.html 是生成 PDF 所需的 PrinceXML 信息:
@page {
margin-left: 0.8cm;
margin-right: 0.8cm;
margin-bottom: 2cm;
margin-top: 4cm;
@top-left {
margin-left: -0.6cm;
margin-right: -0.6cm;
content: url({% static "url" %});
}
@bottom-right {
border-top: solid 1px #bbb;
margin-top: 0.4cm;
vertical-align: middle;
font-size: 8pt;
content: counter(page) "/" counter(pages)
}
@bottom-center {
border-top: solid 1px #bbb;
margin-top: 0.4cm;
vertical-align: middle;
font-size: 8pt;
content: "{% now 'j.m.Y' %}"
}
@bottom-left {
border-top: solid 1px #bbb;
margin-top: 0.4cm;
padding-right: 2cm;
vertical-align: middle;
font-size: 8pt;
content: "footer info"
}
size: A4
}
html {
font-family: Arial, Verdana, Geneva, Helvetica, sans-serif ;
}
div.page-header {
page-break-before: always
}
我的问题是:当我将样式包含到我已经 {% load staticfiles %} 的 HTML 中时,我是否需要在 style.html 中再次加载它?
我的猜测是肯定的,因为正如 Django 文档中所说,包含将使用我的主 html 的上下文呈现 style.html,但 staticfiles 库不是上下文的一部分。我对吗 ?