A Django class-based view generating PDF resposes using WeasyPrint
Switch branches/tags
Nothing to show
Clone or download
Latest commit 059b14b Jul 16, 2018

README.rst

django-weasyprint

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

Installing

Install and update using pip:

pip install -U django-weasyprint

Usage

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

Example

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

Links