【问题标题】:Django- Not displaying a PDF page on the front-endDjango-在前端不显示 PDF 页面
【发布时间】:2020-09-11 07:14:16
【问题描述】:

我正在尝试从“document.HTML”页面中显示 PDF 页面

文件结构是

1.Client2--> 目录 --> 静态 --> 目录 --> 我的 css 文件等

  1. Client2--> 目录--> 模板--> 目录--> 图片(pdf 在这里)和我所有的 .HTML 文件

pdf 被引用为 src..{images/..pdf} 等

文档 HTML 页面

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    {% load static %}
</head>
<body>
<!-- Type is pdf and is located in the documents.html directory aka (catalog) but within a sub-folder 'images'-->
<embed type="application/pdf"
       src="images/Logs_Guide.pdf"
       width="250"
       height="200">

<embed type="application/pdf"
       src="images/AD_Guide.pdf"
       width="250"
       height="200">
<img src="images/ER_Diagram.jpg">

</body>
</html>

但是当我在 Django 前端尝试它并单击我得到的 pdf 时

"GET /catalog/documents/images/Logs_Guide.pdf HTTP/1.1" 404 3366

【问题讨论】:

    标签: django-views django-urls http-get django-settings django-apps


    【解决方案1】:

    1. 所以文档 HTML 加载静态,这意味着所有文件在 静态目录正在加载
    2. 但是,存储 PDf 文件的图像文件夹是 在模板/目录/图像

    3. 所以我需要在 static/catalog/images 中移动这个文件夹并 然后可以将源更改为:

    4. 这是加载静态文件并在(步骤 3) 文件路径中查找文件
    5. 并替换(以下代码) sn-p 并更新到documents.html

    <embed type="application/pdf"
           src="{% static 'catalog/images/Logs_Guide.pdf'%}"
           width="250"
           height="200">
    

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        {% load static %}
    </head>
    <body>
    <!-- Type is pdf and is located in the documents.html directory aka (catalog) but within a sub-folder 'images'-->
    <embed type="application/pdf"
           src="images/Logs_Guide.pdf"
           width="250"
           height="200">
    
    <embed type="application/pdf"
           src="images/AD_Guide.pdf"
           width="250"
           height="200">
    <img src="images/ER_Diagram.jpg">
    
    </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2021-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-07
      • 2021-02-19
      • 2017-10-09
      • 1970-01-01
      • 2021-10-10
      相关资源
      最近更新 更多