首页 > 解决方案 > 从html中的目录链接pdf文件

问题描述

我无法使用 python/django 在我的目录中创建指向 pdf 文档的链接。html 页面中的链接如下所示:

<a href="pilots/12-and-Holding.pdf" target="_blank" Read Me</a>

这是一个 pdf,我想在另一个页面上打开并可供下载。它设置的折叠是pilots/12-and-Holding.pdf。

我哪里错了?我得到的错误是:

 Using the URLconf defined in scripts.urls, Django tried these URL patterns, in this order:

 The current path, pilots/12-and-Holding.pdf, didn't match any of these.

这需要url路径吗?

谢谢,

托尼

标签: pythondjangopdflinkerblank-line

解决方案


@furas 已经解释过了。

我假设您在文件夹pilots下有一个文件static夹来保存您的文件12-and-Holding.pdf

然后在您的模板中,您只需要:

<a href="{% static 'pilots/12-and-Holding.pdf' %}" target="_blank">Read Me</a>

确保您{% load static %}在模板的最顶部。


推荐阅读