0
我在調試狀態,我想呈現一個HTML頁面PrinceXML爲PDF。我需要加載包含的HTML staticfiles在Django?
在我的主要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中時,是否需要使用lo在style.html中再次添加廣告?
我的猜測是肯定的,因爲在Django文檔正如所說,包括將呈現與我的主要HTML的背景下style.html,但staticfiles庫不是上下文的一部分。我對嗎 ?
我的文檔閱讀,但它並沒有回答以下問題:共享所包括的HTML的唯一的事情是上下文變量? – Laurent 2014-10-02 06:22:02
沒錯。 :) – Filly 2014-10-02 06:30:15
謝謝菲莉! – Laurent 2014-10-02 06:32:09