Reputation: 437
I'm trying to create a home media server using Django. For this I want it to be in such a way that my media files are stored in an external USB. Now from my code when I try to load the video, it doesn't work. I even tried hard coding a path to see if it works. When I run through Django, It doesn't work but when I directly open the HTML in chrome It works perfectly.
Placeholder Template Code:
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<video width="640" height="480" controls autoplay>
<source src="E:/Programming\Projects\Youtube Downloader\Ariana Grande - One Last Time (Official).mp4" type="video/mp4">
</video>
<p><b>Note:</b> The autoplay attribute will not work on some mobile devices.</p>
</body>
</html>
Actual Template:
{% extends 'MediaPlayer/layout.html' %}
{% block MainContent %}
{{ video_source}}
<video width="640" height="360">
<source src="E:/OneLastTime.mp4" type="video/mp4">
</video>
<p><b>Note:</b> The autoplay attribute will not work on some mobile devices.</p>
{% endblock %}
{% block PageScripts %}
{% endblock %}
View that calls the template:
def select_video_page(request, video_id):
file_path = FILE_SCANNER.files["video"][video_id]
context = {
"video_source": file_path,
"title": '.'.join(file_path.split("\\")[-1].split(".")[:-1])
}
return render(request, "MediaPlayer/selectvideopage.html", context)
Everything on the page works perfectly fine, Template loads and everything. Only issue i'm facing is with the video file. Almost all the solutions I have found requires storing the Media in a media
directory under Django, But this would defeat the purpose of my project.
Upvotes: 0
Views: 1139
Reputation: 36
If you post your settings.py it will be helpful in determining your problem.
You are trying to serve static media from your Django project. You need to properly specify which directory you want to use as your media root, i.e. your USB drive. Additionally I don't see any non-trivial way to enable the django app to support hot-plugging of the USB drive, this may also lead to other problems if the media is disconnected.
This HTML indicates that you are not serving the files from the Media Server (unless you have defined your MEDIA_URL as E: in settings.py)
Even if you got this url to render a video, it would not work for any other network device unless the file is being served by django's media server given the filesystem path below.
<source src="E:/OneLastTime.mp4" type="video/mp4">
django static file serving guide
You will most likely need to use python's OS module to navigate to the directory on your usb drive and then declare this directory as your media root for django to serve files from it. There may be built in security features that prevent serving files from outside the root of the project.
Upvotes: 1