django-weasyprint
Django WeasyPrint integration
What it is and what it does
Django-WeasyPrint bridges Django's template system with WeasyPrint, a Python library that converts HTML and CSS into PDF documents. It provides both a class-based view mixin (`WeasyTemplateResponseMixin`) and a standalone response class (`WeasyTemplateResponse`) that handle the boilerplate of rendering a Django template to HTML, then converting that HTML to PDF. You use it by inheriting from the mixin in your view, optionally configuring PDF-specific settings like filename and attachment behavior, and the view automatically returns a PDF response instead of HTML.
The package handles URL fetching for resources like stylesheets and images through a customizable `DjangoURLFetcher` that understands Django's static files and URL schemes. It supports both inline PDF display and download-dialog attachment modes, PDF options (like accessibility variants), and dynamic filename generation. The integration is minimal—most of the heavy lifting is delegated to WeasyPrint itself, which means you write standard Django templates and CSS, then get PDFs without extra conversion steps.
Use it for:
- Generate invoices or receipts as PDF downloads from Django template-based views.
- Create printable reports or data exports from Django querysets rendered as styled HTML.
- Build PDF certificates or documents dynamically based on user data in a DetailView.
- Serve inline PDF previews in a web interface without leaving Django.
- Generate PDFs asynchronously in Celery tasks using WeasyPrint's HTML and write_pdf methods.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides Django class-based views and response classes for generating PDF documents from HTML templates using WeasyPrint.
Yes. The package is actively maintained, has low install friction, carries no known vulnerabilities, and uses a permissive license. It is a straightforward, well-tested integration layer for a common need (PDF generation from Django templates). Install it if you need to generate PDFs from Django views or templates.
Install
django-weasyprint on PyPI
pip
pip install django-weasyprintuv
uv add django-weasyprintpoetry
poetry add django-weasyprintInstalling django-weasyprint
Before you install
Low friction install with WeasyPrint bundled as a dependency. Actively maintained with recent commits; last release 126 days ago. Supports current Python versions (3.10–3.14) and Django versions through 6.0.
License in practice
Apache-2.0 permissive license allows commercial and private use with minimal restrictions; suitable for most projects.
Quickstart
pip install django-weasyprint
from django_weasyprint import WeasyTemplateResponseMixin
from django.views.generic import DetailView
class MyPDFView(WeasyTemplateResponseMixin, DetailView):
template_name = 'mymodel.html'
pdf_filename = 'output.pdf'
Requires Django 3.2 or later and Python 3.10 or later. WeasyPrint may require system libraries for font and image rendering depending on your platform.
Verify before relying
- Whether WeasyPrint's switch to pydyf in version 53 (from Cairo) affects PDF output quality or rendering for your use case.
- System-level dependencies needed for WeasyPrint on your target deployment platform.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — Django, WeasyPrint |
| Maintenance | actively maintained — 126 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 248,426/month — #8,666 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_weasyprint-2.5.0-py3-none-any.whl
Keywords: Django, PDF, WeasyPrint
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
weasyprintWeasyPrint converts HTML and CSS into PDF…
permissive · top 1,000 on PyPI
md2pdfConverts Markdown files to PDF with custom CSS…
permissive · top 15,000 on PyPI
mkdocs-with-pdfGenerates a single PDF file from an MkDocs…
permissive · top 15,000 on PyPI
xhtml2pdfConverts HTML and CSS to PDF documents using…
permissive · top 5,000 on PyPI
pydyfpydyf generates PDF documents from Python code…
permissive · top 1,000 on PyPI
django-bracesProvides reusable mixin classes for Django…
permissive · top 15,000 on PyPI
django-wkhtmltopdfWraps the wkhtmltopdf binary to convert HTML to…
permissive · top 15,000 on PyPI
pdfkitPython wrapper for wkhtmltopdf that converts…
permissive · top 5,000 on PyPI
fpdfGenerates PDF documents from Python code,…
copyleft · top 5,000 on PyPI