Solution 1 :

If you post your 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

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.

Problem :

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>
    <title>Title of the document</title>
    <video width="640" height="480" controls autoplay>
      <source src="E:/ProgrammingProjectsYoutube DownloaderAriana Grande - One Last Time (Official).mp4" type="video/mp4">
    <p><b>Note:</b> The autoplay attribute will not work on some mobile devices.</p>

Actual Template:

{% extends 'MediaPlayer/layout.html' %}

{% block MainContent %}
    {{ video_source}}
    <video width="640" height="360">
        <source src="E:/OneLastTime.mp4" type="video/mp4">
    <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.


Comment posted by Samay Gupta

Setting the MEDIA_ROOT to E:/ Worked, Thanks. As for the hot plugging, I’m going to run this on a raspberry pi so i’ll have a wrapper script to take care of that