We need an HTML document as input for WeasyPrint. We are going to create an HTML template, render it using Django, and pass it to WeasyPrint to generate the PDF file.
Create a new template file inside the templates/orders/order/ directory of the orders application and name it pdf.html. Add the following code to it:
<html> <body> <h1>My Shop</h1> <p> Invoice no. {{ order.id }}</br> <span class="secondary"> {{ order.created|date:"M d, Y" }} </span> </p> <h3>Bill to</h3> <p> {{ order.first_name }} {{ order.last_name }}<br> {{ order.email }}<br> {{ order.address }}<br> {{ order.postal_code }}, {{ order.city }} </p> <h3>Items bought</h3> <table> <thead> <tr> <th>Product</th> <th>Price</th> <th>Quantity</th> ...