--- id: django-weasyprint version: "2.5.0" license: Apache-2.0 license_treatment: permissive maintenance: active --- # django-weasyprint — Django WeasyPrint integration License: permissive · Maintenance: active · Downloads: 248.4K/mo ## 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 above — 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 pip install django-weasyprint uv add django-weasyprint 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_current - Install friction: low - Maintenance: active - Downloads: 248.4K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags django pdf generation, weasyprint django integration, html to pdf django, django template pdf export, class-based view pdf, django pdf response, template-based pdf rendering, pdf-generation, django-integration [View on SkillFed](https://skillfed.io/packages/django-weasyprint) · [View on PyPI](https://pypi.org/project/django-weasyprint/)