If you are running into problems, please refer to the Pillow’s installation guide. Sometimes it is a pain to get it installed. It relies on Pillow, which is a third-party Python Image Library. Using ReportLab Installation pip install reportlab You can change the Content-Disposition to: response = 'inline filename="mypdf.pdf"' If you want to display the PDF in the browser This way the user will be prompted with the browser’s open/save file. open ( filename ) as pdf : response = HttpResponse ( pdf, content_type = 'application/pdf' ) response = 'attachment filename="mypdf.pdf"' return response else : return HttpResponseNotFound ( 'The requested pdf was not found in our server.' ) from import FileSystemStorage from django.http import HttpResponse, HttpResponseNotFound def pdf_view ( request ): fs = FileSystemStorage () filename = 'mypdf.pdf' if fs. The FileSystemStorage sets the base_url to the project’s MEDIA_ROOT. It will also work if you simply use open() In the example below I’m using the Django’s FileSystemStorage class. ![]() ![]() Then I will show how to use ReportLab and WeasyPrint. ![]() First I will show how to return a PDF response, which can also be used if you are just All of them requires a third-party library so to There are a few ways to export data to a PDF file using Django.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |