So here is my html code for the pdf
<div class="cont">
<img class="logo1" src="{% static 'upload/' %}{{ wmsu_logo.img_name }}" />
<div>
<p>Republic of the Philippines</p>
<p>Western Mindanao State University</p>
<p>{{ syllabus.college }}</p>
<p class="title">DEPARTMENT OF {{ syllabus.department }}</p>
</div>
<img class="logo2" src="{% static 'upload/' %}{{ course_logo.img_name }}" />
<img class="logo3" src="{% static 'upload/' %}{{ iso_logo.img_name }}" />
</div>
and this is the view where it processes things.
def pdf(request, id):
# ---------- SYLLABUS ----------
syllabus = get_object_or_404(Syllabus, user_id=request.user, id=id)
# ---------- SYLLABUS TEMPLATE ----------
syllabus_template = get_object_or_404(Syllabus_Template, user_id=request.user, id=syllabus.syllabus_template_id.id)
wmsu_logo = Logo.objects.get(syllabus_template_id=syllabus_template, name='wmsu_logo')
course_logo = Logo.objects.get(syllabus_template_id=syllabus_template, name='course_logo')
iso_logo = Logo.objects.get(syllabus_template_id=syllabus_template, name='iso_logo')
total_term_percentage = midterm.term_percentage + finalterm.term_percentage
template = loader.get_template('PDF_template/template.html') # Load HTML template
html_string = template.render({
'wmsu_logo': wmsu_logo,
'course_logo': course_logo,
'iso_logo': iso_logo,
}) # Render the template
# Generate the PDF using WeasyPrint
pdf = HTML(string=html_string, base_url=request.build_absolute_uri()).write_pdf()
# Create an HttpResponse with the PDF content
response = HttpResponse(pdf, content_type='application/pdf')
# Display in the browser
response['Content-Disposition'] = 'inline; filename=Syllabus' + str(datetime.datetime.now()) + '.pdf'
return response
I need the uploaded image in the pdf conversion in weasyprint. I already deployed this in pythonanywhere. When I use the local file the image renders but when I deploy it, it does not render the image. I tried every possible way. Please recommend a fix to this I really need it. Please help.