如何在django中的打印页面(模板)中设置背景图像

时间:2013-06-11 07:04:24

标签: html css django django-templates

CSS:

table.print{
    width:123px;
    height:298px;
    background-position:center;
    background:url('{{ STATIC_URL }}images/human.png'); 
}

HTML:

<table id="human-body" class="print" >
    <tr>
        <td>some data</td>
    </tr>
</table>

上面的HTML在我的应用程序中用作django中的打印模板。我的问题是,我使用上面的CSS将背景图像应用于打印页面。但是,如果我按下打印按钮并看到打印预览,则背景图像会丢失。我检查了用纸打印它,图像丢失了。

2 个答案:

答案 0 :(得分:1)

如果您要打印背景图片,请按照以下步骤进行操作

1.要在Chrome和Safari网络浏览器中启用后台打印,请添加

-webkit-print-color-adjust:exact;

在你的print.css文件中,rest all是相同的

2.在FireFox默认情况下"Print Background colours and images"在其打印设置中关闭no CSS will override that.

如果需要背景图片,用户应手动开启。

在FF中打开背景的步骤:

Go to File -->Page setup -->Formats & Options -->Tick Print background(images & colors)

答案 1 :(得分:0)

您不能在css文件中使用STATIC_URL。您只能在模板中使用它。