【发布时间】:2020-01-19 07:51:13
【问题描述】:
我正在尝试使用 Django 创建家庭媒体服务器。为此,我希望它的媒体文件存储在外部 USB 中。现在,当我尝试加载视频时,从我的代码中,它不起作用。我什至尝试对路径进行硬编码,看看它是否有效。当我通过 Django 运行时,它不起作用,但是当我直接在 chrome 中打开 HTML 时,它工作得很好。
占位符模板代码:
<!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>
实际模板:
{% 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 %}
调用模板的视图:
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)
页面上的一切都运行良好,模板加载和一切。我面临的唯一问题是视频文件。我发现的几乎所有解决方案都需要将媒体存储在 Django 下的 media 目录中,但这会违背我的项目目的。
【问题讨论】:
标签: python html django python-3.x