This is my view:
from django.conf import settings from django.http import HttpResponse from django.template.loader import render_to_string import weasyprint
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
http://weasyprint.readthedocs.io/en/latest/install.html#linux