Django App – Button Download home page to pdf

Question:

i am working on an django App

On my html page " results.html "
i want to add a button to download the page to pdf

How is it possible, please ?
What i have to write in the fonction" download_pdf" in the file views.py?

.html :

<a class="btn btn-primary" href="{% url 'download_pdf' %}" role="button">Download pdf</a>

urls.py

from django.urls import path
from . import views

urlpatterns = [
    path('', views.home),
    path('views.download_my_pdf', views.download_pdf, name="download_pdf"),

]

views.py :

def download_pdf(request):

        return response



Asked By: Pandas

||

Answers:

You can convert a HTML page to a PDF on-the-fly and send its result as a response in Django with Django Weasyprint. E.g., have a look at the examples with WeasyTemplateResponseMixin.

Answered By: sauerburger

I ran into the same issue and found a great way to hand html to pdf conversion using a reply in another stack over flow answer try this

Answered By: Audrey
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.