python - 从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路径吗?
谢谢,
托尼
解决方案
@furas 已经解释过了。
我假设您在文件夹pilots
下有一个文件static
夹来保存您的文件12-and-Holding.pdf
然后在您的模板中,您只需要:
<a href="{% static 'pilots/12-and-Holding.pdf' %}" target="_blank">Read Me</a>
确保您{% load static %}
在模板的最顶部。
推荐阅读
- php - 忽略值 $request == null
- java - 从最近刷入应用程序后,CountDownTimer 未在服务中运行?
- vba - VBA 不会将 vba 参考转换为 excel 参考
- java - 安卓代码格式
- c++ - How to let clang-format format c++ long for loop into three lines?
- javascript - Onlick doesn't work
- react-native - In react native how to display dropbox entries in react native App
- swift - Vapor 3 - 搜索失败时返回不同的未来?
- asp.net-mvc - How to handle query string in Asp.net MVC 5
- python - 如何使用python从json文件中获取参数