skillfed

django-weasyprint

Django WeasyPrint integration

django-weasyprint v2.5.0 248.4K downloads/30d#8,666 on PyPI402
Permissive license Apache-2.0 Active released

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-weasyprint

uv

uv add django-weasyprint

poetry

poetry add django-weasyprint

Installing 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

Development Status :: 5 - Production/StableEnvironment :: Web EnvironmentFramework :: DjangoFramework :: Django :: 3.2Framework :: Django :: 4.2Framework :: Django :: 5.2Framework :: Django :: 6.0Intended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Internet :: WWW/HTTP :: Dynamic ContentTopic :: Software Development :: Libraries :: Python Modules

Tags

django pdf generationweasyprint django integrationhtml to pdf djangodjango template pdf exportclass-based view pdfdjango pdf responsetemplate-based pdf rendering
pdf-generationdjango-integration

More Python Modules packages