如何使用django格式化动态生成的HTML



我正在尝试创建一张标签,用二维码、徽标和电话号码打印出来,二维码是从xlsx文件中单独生成的,它们可以工作。我的问题是在HTML中格式化它们。我不知道如何更改for循环,所以每次将图像加载到标签上时,它都会创建一行。这是代码的html部分:

{% load static %}
<html lang="en">
<head>
<meta charset="UTF-8">
<title>labels</title>
<style>
</style>
</head>
<link rel="stylesheet" type="text/css" href="{% static '/css/style.css' %}"/>
<table width="150" cellpadding="2" cellspacing="1">
<tr>
{% for item in list_qr_images %}
<img src="{% static 'inc.png' %}" align="center"/>
<img src="{{ item }}" align="center">
<p style="text-align:left">(718) 280-0000</p>
{% endfor %}
</tr>
<tr></tr>
</table>
</br>
</html>

经过多次尝试和错误,我发现了问题。以下是格式化为修复的代码和Avery 61523表,以防将来有人发现它有用。

{% load static %}
<html lang="en">
<head>
<meta charset="UTF-8">
<title>labels</title>
<style>
<!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;
mso-font-charset:0;
mso-generic-font-family:roman;
mso-font-pitch:variable;
mso-font-signature:3 0 0 0 1 0;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;
mso-font-charset:0;
mso-generic-font-family:swiss;
mso-font-pitch:variable;
mso-font-signature:-469750017 -1073732485 9 0 511 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-unhide:no;
mso-style-qformat:yes;
mso-style-parent:"";
margin-top:0in;
margin-right:0in;
margin-bottom:8.0pt;
margin-left:0in;
line-height:107%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:Calibri;
mso-fareast-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
.MsoChpDefault
{mso-style-type:export-only;
mso-default-props:yes;
font-family:"Calibri",sans-serif;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:Calibri;
mso-fareast-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
.MsoPapDefault
{mso-style-type:export-only;
margin-bottom:8.0pt;
line-height:107%;}
@page WordSection1
{size:8.5in 11.0in;
margin:.55in .3in 3in .55in;
mso-header-margin:.1in;
mso-footer-margin:.12in;
mso-paper-source:4;}
div.WordSection1
{page:WordSection1;}
-->
</style>
<xml>
<o:shapedefaults v:ext="edit" spidmax="1026"/>
</xml><![endif]--><!--[if gte mso 9]>
<xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1"/>
</o:shapelayout>
</xml><![endif]-->
</head>
<link rel="stylesheet" type="text/css" href="{% static '/css/style.css' %}"/>
<table class=MsoTableGrid border=0 cellspacing=0 cellpadding=0
style='margin-left:-.75pt;border-collapse:collapse;border:none;mso-padding-top-alt: 0in;mso-padding-bottom-alt:0in;mso-border-insideh:none;mso-border-insidev: none'>
{% for item in list_qr_images %}
<tr style='mso-yfti-irow:0;mso-yfti-firstrow:yes;page-break-inside:avoid; height:47.5pt'>
<img src="static/images/0'qr.jpg" align="center" style=" padding-left: 3px; padding-right: 30px; padding-bottom: 20px; padding-top: 20px;">
</tr>
{% endfor %}
</table>
</br>
</html>

我使用word生成了一个标签页,然后将其转换为HTML格式,并将其编辑为所需的大小。

最新更新