this is the first time i'm using reportlab. i copied the exact code from django documentation. https://docs.djangoproject.com/en/2.1/howto/outputting-pdf/. when i save the file its getting saved as plain text document (text/plain). the name remains the same hello.pdf.
p = canvas.Canvas(buffer) in this line if i specify the name of file 'hello.pdf' instead of buffer and remove the buffer from the fileresponse method it works and automatically gets saved as pdf file, but i cannot prompt the user to save the file. buffer = io.BytesIO() # Create the PDF object, using the buffer as its "file." p = canvas.Canvas(buffer) print(type(p)) # Draw things on the PDF. Here's where the PDF generation happens. # See the ReportLab documentation for the full list of functionality. p.drawString(100, 100, "Hello world.") # Close the PDF object cleanly, and we're done. p.showPage() p.save() print(type(p)) # FileResponse sets the Content-Disposition header so that browsers # present the option to save the file. return FileResponse(buffer, as_attachment=True, filename='hello.pdf') i tried specifying the content_type='application/pdf' on the code provided by django documentation but it still gets saved as plain text document. i'm guessing the File response cannot guess the type of file from the filename argument as mentioned in django documentation. *class *FileResponse(*open_file*, *as_attachment=False*, *filename=''*, ***kwargs)* if open_file doesn’t have a name or if the name of open_file isn’t appropriate, provide a custom file name using the filename parameter. The as_attachment and filename keywords argument were added. Also, FileResponse sets the Contentheaders if it can guess them. If i use the code from 2.0 django documentation it works. is there a bug in the latest django documentation 2.1? i installed all the dependencies according to this official link https://bitbucket.org/rptlab/reportlab/src/927995d54048767531a4ad4a0648e46064b0c4c7/README.txt?at=default&fileviewer=file-view-default environment- ubuntu 18.04lts , pycharm, Python 3.5.6, reportlab 3.5.12. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d67b7502-0426-41da-a8fd-e793791a394b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.