使用django在html中嵌入视频对象

时间:2018-01-23 16:41:38

标签: html django

我无法将云中的视频内容文件嵌入到我的网页中。

我正在使用Django框架进行开发

我正在使用pyrax从Rackspace云获取文件。

这是我的代码:

def getfile(request):
 file =  object.fetch() // this return the file content of video file that's stored in cloud
 return render(request,'index.html',{'file':file})

我的HTML

{% if file%} <video height='320' width='320' controls> <source src='file:'{{file}} type='video/mp4'> </video> {% endif %}

使用上面的代码我收到错误

  

找不到支持格式和MIME类型的视频

任何人都可以帮我这个, 提前致谢

1 个答案:

答案 0 :(得分:0)

创建两个视图功能,其中一个视图用于呈现HTML,另一个视图返回视频的响应。

<video controls='true' height="320" width="320">
        <source src="{% url 'returnVideo' %}" type="video/mp4">
</video>

要使它们以HTML格式显示,我们可以为returnVideo视图提供源URL

\x

这种方法没有任何问题。