Issue
On a flask site, link to download pdf is provided on the page.
When i run the site by main.py i get the file doesn't exist error as given under,
but it works fine when i run only index.html file
in main.py
class ThePage(MethodView):
def get(self):
form = InfoForm()
return render_template("index.html")
in 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>
Problem may be related to render_template part where i should add some arguments, though i couldn't figure out how to.
Solution
I think you are using a relative path to the templates directory. The server cannot resolve this URL. Use the static
folder to deliver static files.
- Move the pdf file to a folder called
static
within your application's root directory. - Inside the anchor tag use
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>
Answered By - Detlef
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.