I'm using django 1.8 in python 2.7.

I want to show a pdf in a template.

Up to know, thanks to MKM's answer I render it in a full page.

Do you know how to render it?

Here is my code:

def userManual(request):

with open('C:/Users/admin/Desktop/userManual.pdf', 'rb') as pdf:

response = HttpResponse(pdf.read(), content_type='application/pdf')

response['Content-Disposition'] = 'inline;filename=some_file.pdf'

return response

pdf.closed

解决方案

The ability to embed a PDF in a page is out of the scope of Django itself, you are already doing all you can do with Django by successfully generating the PDF, so you should look at how to embed PDFs in webpages instead:

Therefore, please check:

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐