0

I am using weasyprint it working on window perfectly and also it is working on linux when I used this string in html file like weasyprint my.html my.pdf It perfectly show image but when I do the below code so the image not showing I


html_string = '<img src="http://domain_name/static/assets/images/logo/logo.png" alt = "Logo" /> <h1>images</h1>' # Create a PDF object from the HTML string
#pdf = weasyprint.HTML(string= html_string, base_url=request.build_absolute_uri()).write_pdf(presentational_hints = True, stylesheets=[weasyprint.CSS(string='@page { size: letter; }')])

# # Create an HTTP response with the PDF content
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="marksheet.pdf"'
response.write(pdf)
return response

I used absolute_url but not showing images nothing get any idea why it not showing image

1 Answers1

0

I am using Django and Nginx on a live server. Initially, I was facing issues with images not loading. After debugging and searching, I realized that the root cause of the problem was related to the SSL certificate. When I installed an SSL certificate and attempted to load images using links with my domain's HTTPS, the images started loading properly.

I would like to share my solution with others so that they can benefit from it and resolve similar image loading issues.

Solution (What You Did and How It Worked):

I installed an SSL certificate and configured Nginx on my server. Then, I updated the image URLs to start with https and attempted to load them again. This resolved the issue, and the images started loading correctly.

Technologies Used (Django, Nginx, SSL, etc.):

  • Django
  • Nginx
  • SSL Certificate

How This Solution Can Help Others:

This solution could be helpful for developers facing similar issues with SSL certificates and images not loading. By sharing my experience, I hope to assist others in resolving similar problems.