小编Zig*_*gko的帖子

需要帮助使用 xhtml2pdf 从模板渲染 pdf 中的 img

我正在构建一个项目,我需要将数据从模板(html)转换为pdf,我的问题是图像没有出现在pdf视图上。这是我的代码:

class GeneratePdf_month(TemplateView):

    template_name = "polls/info_month.html"

    def get(self, request, *args, **kwargs):
        ## do some....
        data = {
            'cliente': cliente,
        }
        pdf = render_to_pdf(self.template_name, data)
        return HttpResponse(pdf, content_type='application/pdf')


## and this is my html template
<head>
    {% load staticfiles %}
    <title>Detail</title>
    <style>
        table, th, td {
          border: 1px solid black;
          border-collapse: collapse;
          padding: 10px;
        }

    </style>
</head>
<body>
    <header>BlaBla<img src="{% static 'polls/images/image.png'%}"></header>
</body
Run Code Online (Sandbox Code Playgroud)

有人能帮我吗?

django xhtml2pdf

3
推荐指数
1
解决办法
3087
查看次数

标签 统计

django ×1

xhtml2pdf ×1