This is my view:
from django.conf import settings
from django.http import HttpResponse
from django.template.loader import render_to_string
import weasyprint
If you are getting this error when using weasyprint, then you may have forgotten to install Pango, GdkPixbuf, and cairo dependencies of weasyprint which cannot be installed using pip/pip3
For Debain/Ubuntu
sudo apt-get install build-essential python3-dev python3-pip python3-setuptools python3-wheel python3-cffi libcairo2 libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 libffi-dev shared-mime-info
For other platforms refer the below link
https://weasyprint.readthedocs.io/en/latest/install.html