Skip to main content
Join the official Python Developers Survey 2018 and win valuable prizes: Start the survey!

Django WeasyPrint CBV

Project description

A Django class-based view generating PDF responses using WeasyPrint.


Install and update using pip:

pip install -U django-weasyprint


Use WeasyTemplateView as class based view base class or the just the mixin WeasyTemplateResponseMixin on a TemplateView (or subclass thereof).


from django.conf import settings
from django.views.generic import DetailView

from django_weasyprint import CONTENT_TYPE_PNG, WeasyTemplateResponseMixin

class MyModelView(DetailView):
    # vanilla Django DetailView
    model = MyModel
    template_name = 'mymodel.html'

class MyModelPrintView(WeasyTemplateResponseMixin, MyModelView):
    # output of DetailView rendered as PDF
    pdf_stylesheets = [
        settings.STATIC_ROOT + 'css/app.css',

class MyModelImageView(WeasyTemplateResponseMixin, MyModelView):
    # generate a PNG image instead
    content_type = CONTENT_TYPE_PNG

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
django_weasyprint-0.5.4-py2.py3-none-any.whl (7.1 kB) Copy SHA256 hash SHA256 Wheel py2.py3 Jul 16, 2018
django-weasyprint-0.5.4.tar.gz (4.9 kB) Copy SHA256 hash SHA256 Source None Jul 16, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page