I am trying to generate a PDF file out of a post created by a user, and include an image, which I want to store in an AWS bucket.
This is how it was working with my own file system
My function to generate a pdf in views.py:
def form_render_pdf_view(request, *args, **kwargs):
pk = kwargs.get('pk')
form = get_object_or_404(Post, pk=pk)
template_path = 'form/pdf2.html'
context = {
'form': form
}
# Create a Django response object, and specify content_type as pdf
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'filename="report.pdf"'
# find the template and render it.
template = get_template(template_path)
html = template.render(context)
# create a pdf
pisa_status = pisa.CreatePDF(
html, dest=response)
if pisa_status.err:
return HttpResponse('We had some errors <pre>' + html + '</pre>')
return response
And rendering the image in the html template
<div>
<img src="{{form.image.path}}">
</div>
Now after uploading the files in a bucket it doesn't seem to work. The image is being stored there after uploading the post, but when creating the PDF the image is not displayed.(And it gives me an error: This backend doesn't support absolute paths). I tried to change the image source in the HTML template but it still didn't work.