Weasyprint img и шрифт загружаются неправильно

Необходимо исправить конфиг шрифта и статическое изображение

Я пытаюсь связать шрифт Poppins google с рендерингом pdf. В какой-то момент во время тестирования у меня все получилось, но теперь я продвинулся дальше и не могу заставить шрифт загрузиться.

Кроме того, мне удалось разместить изображения в pdf, которые передаются как контекст из режима, но статическое изображение и логотип, которые я разместил в нижней части шаблона, не отображаются, и я не могу связать их правильно.

шаблон

<!DOCTYPE html>
<html lang="en">
    {% load static %}
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Foodstah - {{title}}</title>
</head>
<body>
    <h1>{{post.title}}</h1>
    <h3>by @{{post.author}}</h3>

    <img src="http://127.0.0.1:8000{{post.main_image.url}}" alt="">

    <br>
    <br>
    <h4 class="inline">Time:</h4> <p class="inline">{{post.cooking_time}}</p>
    <h4>Ingredients</h4>
    <p>{{post.ingredients}}</p>
    <h4>Instructions</h4>
    <p>{{post.recipe_description}}</p>
    
    <footer>
        <img class="inline" src="{% static 'images/F_blue.png' %}" alt="">
        <p class="inline">Recipes from around the globe, powered by Foodstah.</p>
    </footer>
</body>
</html>

views.py

def recipe_to_pdf(request, slug):
    recipe = Post.objects.get(slug=slug)
    title = recipe.title
    context = {}
    context["post"] = recipe

    font_config = FontConfiguration()
    html_template = render_to_string('post/pdf_template.html', context=context)
    html = HTML(string=html_template)
    css = CSS(
        string="""
        @font-face {
    font-family: Poppins;
    src: url(https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,200;0,400;0,700;0,800;1,200;1,400;1,900);
}

@page {
    size: A4; /* Change from the default size of A4 */
    margin: 40px; /* Set margin on each page */
}

body {
    font-family: Poppins;
}
h1 {
    font-weight: 800;
    font-size: 44px;
    text-align: center;
    margin-bottom: 0;
    padding-bottom: 0;
}
h3 {
    margin-top: 0;
    padding-left: 80px;
    font-weight: 800;
    font-size: 28px;
    text-align: center;
}

img {
    display: block;
    margin: auto;
    max-width: 300px;
    max-height: 300px;
}

.inline {
    display: inline-block;
    margin: 0;
}

footer {
    display: block;
    position: fixed;
    bottom: 0px;
    left: 20px;
}
""",
        font_config=font_config,
    )
    pdf_file = html.write_pdf(stylesheets=[css],
        font_config=font_config)

    
    response = HttpResponse(pdf_file, content_type='application/pdf')
    filename = f"Foodstah - {title}.pdf"
    content = f"attachment; filename={filename}"
    response['Content-Disposition'] = content
    return response
Вернуться на верх