Image in template.html mit Jinja2 und WeasyPrint in einem PDF rendern

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Image in template.html mit Jinja2 und WeasyPrint in einem PDF rendern

by Anonymous » 14 Apr 2025, 12:08

Ich habe eine Python-Datei, die eine HTML-Seite (und eine PDF) mit Jinja2 wie diesem generiert.

Code: Select all

import pandas as pd
import requests
from jinja2 import Environment, FileSystemLoader
from weasyprint import HTML

# Stuff to get dataframe...

# Generate PDF and csv
env = Environment(loader=FileSystemLoader('.'))
template = env.get_template("template.html")

template_vars = {"title" : "Something...",
"vulnerabilities_table": df.to_html(index=False)}

html_out = template.render(template_vars)
HTML(string=html_out).write_pdf("report_styled.pdf", stylesheets=["style.css"])
Es wird die folgende Vorlage verwendet.

Code: Select all

{% block layout_style %}
 @page { size: letter landscape; margin: 2cm; } 

{% endblock %}



{{ title }}


[img]static/images/Logo.png[/img]
{{ title }}
{{ vulnerabilities_table }}


< /code>
Das [url=viewtopic.php?t=20324]Problem[/url] ist, dass das Bild überhaupt nicht rendert (aber der Rest tut es). Ich denke, es liegt daran
[img]static/images/Logo.png[/img]
Mein Bild befindet sich im Ordner static/mictures/logo.png. Was habe ich falsch gemacht?

Top