I am attempting to redirect a URL in Flask. e.g : localhost/x/e/f/i.mp4
. Where e and f are integer inputs (There isn't an actual file) to a another URL, which actually has the file name i.mp4
. e.g localhost/static/i.mp4
.
This URL is part of a request in a template. But with the template, it will request i.mp4, which is localhost/e/f/i.mp4
. I have tried using add_url_rule with the endpoint being redirect_to=send_from_directory(something)
, send_from_directory
after the template, send_from_directory
before the template, but that only sends the mp4.
The current snippet for Flask is this.
@app.route('/watch/<int:s>/<int:ep>/', methods=['GET'])
def vid(s,ep):
return app.add_url_rule(f'/watch/{s}/{ep}/S{s}-{ep}sub.m4v', redirect_to=send_from_directory('static', f'S{s}-{ep}sub.m4v'))
def sub(s, ep):
return app.add_url_rule(f'/watch/{s}/{ep}/S{s}-{ep}.vtt', redirect_to=send_from_directory('static',f'S{s}-{ep}.vtt'))
def watch(s, ep):
return render_template('watch.html', s=s, ep=ep)
The template is this:
<!DOCTYPE html>
<html lang="en" style="height:100%;">
<head>
<title>{{s}}-{{ep}}</title>
</head>
<body style="margin:0; text-align: center; height:100%;">
<video autoplay=" "controls="" style="margin: 0 auto; height:100vh;">
<source src="S{{s}}-{{ep}}sub.m4v" type="video/mp4">
<track label="English" kind="subtitles" srclang="en" src="S{{s}}-{{ep}}.vtt" default>
</video>
</body>
</html>