JourneyJoker/pdf/views.py
Klaus-Uwe Mitterer a3d31c5cc3 Implement PDF generator
Improve mail view
Implement voucher generation
2021-05-31 07:20:27 +02:00

23 lines
No EOL
679 B
Python

from django.views.generic.base import ContextMixin
from django.template.loader import render_to_string
from django.template.exceptions import TemplateDoesNotExist
from django.core.mail import EmailMultiAlternatives
from django.conf import settings
from html.parser import HTMLParser
from bs4 import BeautifulSoup
import pdfkit
class PDFView(ContextMixin):
template_name = None
def render_to_html(self, **kwargs):
context = self.get_context_data(**kwargs)
return render_to_string(self.template_name, context)
def render(self, **kwargs):
html = self.render_to_html(**kwargs)
pdf = pdfkit.from_string(html, False)
return pdf