Issue
So I am using Flask's send_from function to read a video file to the website. But I need to add extra HTML becuase the send_from function just returns the video and I can't figure out how to render another piece of html to go on top of that such as a nav bar.
Here is my current function:
@app.route("/get_file/<filename>")
def get_file(filename):
ft = send_file(filename)
return ft
Also in a different html file I have a nav-bar in it. Can anyone tell me how to render both of the files at the same time? Please let me know if you need any other pieces of info.
So my question is basically how can I render my nav-bar and the file at the same time.
Solution
You can't do this in one endpoint, instead create 2 sepearte ones, something like this:
@app.route("/get_file_contents/<filename>")
def get_file_contents(filename):
ft = send_file(filename)
return ft
@app.route("/get_file/<filename>")
def get_file(filename):
return f"<video src=\"{escape(url_for(get_file_contents, filename)))}\">"
One will return the html containing the video element, including a navbar and whatever other stuff you desire. Another will send the actual data of the video.
Answered By - mousetail
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.