I am trying to load a pdf in an iframe, i make a backend call to fetch the file name and file path.
I then pass that path to the front end to render within the src tag, but then it mentions something about.
Not Found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
File path:
@auth.route("/building/view-file")
def view_file():
filename = request.args.get("file")
building = request.args.get("building")
document = Document.query.filter_by(name=filename).first()
print(document.path)
return render_template(
"building/Building/view_file.html", document=document.path, building=building
)
Html code:
<iframe src="{{ document }}"></iframe>
<button class="tenant_card_buttons" hx-get="/auth/building-info-expanded" hx-
vals='{"building":"{{building}}"}'
hx-target="#modal">Back</button>
<button class="tenant_card_buttons" onclick="closeModal()">Close</button>
Server logs:
FILE_STORAGE/Matric_Certificate.pdf
127.0.0.1 - - [28/Apr/2024 17:23:33] "GET /auth/building/view-file?
file=Certificate.pdf&building=1 HTTP/1.1" 200 -
127.0.0.1 - - [28/Apr/2024 17:23:33] "GET /auth/FILE_STORAGE/Matric_Certificate.pdf
HTTP/1.1" 404 -
What am i doing wrong? why does the src then query the db again?