Display an image on my pdf generate with render_to_pdf

I would like to display an image on my pdf that I generated from information


class GeneratePdf(View):
    def get(self, request, *args, **kwargs):
       pdf = render_to_pdf('cart/commande.html',data)
       return HttpResponse(pdf, content_type='application/pdf')


from io import BytesIO
from django.http import HttpResponse
from django.template.loader import get_template

from xhtml2pdf import pisa

def render_to_pdf(template_src, context_dict={}):
  template = get_template(template_src)
  html  = template.render(context_dict)
  result = BytesIO()
  pdf = pisa.pisaDocument(BytesIO(html.encode("UTF-8")), result)
  if not pdf.err:
     return result.getvalue()
  return None


{% load static %}
    <div class='wrapper'>
        <div class='header'>
            <p class='title'>Invoice # </p>
            <img src="{% static 'images/tof.png' %}" style="width:100px;height: 100px;">
    <div class='details'>
        name: {{name}}<br/>
        age: {{age}} <br/>
        service: {{service}}
        <hr class='hrItem' />

I cannot display the image, at the level of the pdf document it is mentioned at the level of the execution console,

Need a valid file name

I managed to display the image on the pdf, by doing:


<img src="static/images/tof.png" style="width:100px;height: 100px;">


Back to Top