【问题标题】:How to show multipul pdf's in django view如何在 django 视图中显示多个 pdf
【发布时间】:2018-02-15 19:06:58
【问题描述】:

是否可以在 Django 视图中显示多个 PDF 文件,而不仅仅是一个?

我当前的视图只显示一个

class PdfView(View):
    def get(self, request, *args, **kwargs):
        for pdf in pdfs:
            with open('/path/to/pdf/file/' + pdf.title + '.pdf', 'r') as pdf:
                response = HttpResponse(pdf.read(), content_type='application/pdf')
                response['Content-Disposition'] = 'inline; filename=' + pdf.title + '.pdf'
                return response

我想根据需要打开尽可能多的 pdf,但经常遇到 HTTP ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION

编辑:这是回溯

Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 86, in run
    self.finish_response()
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 128, in finish_response
    self.write(data)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 217, in write
    self._write(data)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 328, in write
    self.flush()
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 307, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 41] Protocol wrong type for socket

【问题讨论】:

  • @MEE 对此感到抱歉。现在应该修好了。

标签: python django http-headers django-views


【解决方案1】:

我认为你可以使用简单的寺庙视图和 html iframe。

【讨论】:

    猜你喜欢
    • 2012-07-31
    • 2014-11-24
    • 1970-01-01
    • 1970-01-01
    • 2018-02-17
    • 1970-01-01
    • 2015-02-20
    • 2017-09-13
    • 1970-01-01
    相关资源
    最近更新 更多