Django-不在前端显示PDF页面

问题描述 投票:0回答:1

我正在尝试从'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个回答
0
投票

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

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

  4. 这是静态加载,并在((第3步)文件路径中找到文件] >>
  5. 并替换(以下代码)
  6. 代码段并更新到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>
© www.soinside.com 2019 - 2024. All rights reserved.