在燒瓶網站上,頁面上提供了下載 pdf 的鏈接。
當我通過main.py運行網站時,我得到檔案不存在的錯誤,如下所示,
但是當我只運行index.html檔案時它作業正常
錯誤
在 main.py 中
class ThePage(MethodView):
def get(self):
form = InfoForm()
return render_template("index.html")
在 index.html 中
<a href="../1668671114.892154.pdf" download>
<div class="btn-block2">
<span class="hazir">✅</span> <span style="font-size: 20px">PDF ready, click.</span>
</div>
</a>
問題可能與 render_template 部分有關,我應該在其中添加一些引數,但我不知道該怎么做。
uj5u.com熱心網友回復:
我認為您使用的是模板目錄的相對路徑。服務器無法決議此 URL。使用static檔案夾傳遞靜態檔案。
- 將 pdf 檔案移動到
static應用程式根目錄中名為的檔案夾。 - 在錨標簽內使用
url_for('static', filename='1668671114.892154.pdf')
<a href="{{ url_for('static', filename='1668671114.892154.pdf') }}" download>
<div class="btn-block2">
<span class="hazir">✅</span> <span style="font-size: 20px">PDF ready, click.</span>
</div>
</a>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/536270.html
