Reputation: 11
I am trying to take files from an external hard drive and use it in my HTML pages. Since i am using Flask as my frame work i am having great difficult accessing anything outside of the virtual environment. I have tried to change the static folder but i have found no effective way of completing this. It would be great if there is a way that i can route all HTML static files to my external hard drive. At the moment everything is working accept the video file.
So far my init.py looks like this
from flask import Flask
app = Flask(__name__)
app.config.from_object('config')
from app import views
And my html file looks like this
<!DOCTYPE html>
<html>
<head>
<style>
body {background-image: url(static/B1.jpg);}
</style>
<title>Server</title>
</head>
<body>
<video width="original" height="original" controls>
<source src="static/movie.mp4" type="video/mp4">
</video>
</body>
</html>
Thanks for the help everyone :) could i change the html to src to something like this
<source src="../../../../../E:/Movies/movie.mp4" type="video/mp4">
And if i can't why does that work with just opening an html with that source?
I think my problem is that flask can't route a file to the html is there a way to route the file?
Upvotes: 1
Views: 2228
Reputation: 29581
All static files must be in static
folder. Some oprions you have:
static
folder but I can't test right now , on Windows I doubt this will work (on Linux very likely that symbolic links would work).flask.send_file
and flask.send_file_from_directory
: as long as your database contains a mapping of file ID's to file paths, and you put the file ID's in the HTML served to client, then when client requests the file, your flask app uses the ID in the URL to determine file location and uses flask.send_file_from_directory
to serve the file. Upvotes: 3