使用 Django 开发服务器时 HTML5 视频元素不可搜索
我有一个 Django 应用程序,提供带有 HTML5 元素的网页。有一个奇怪的“功能”,将视频元素变成不可搜索:video.seekable
返回一个timeRanges
对象,其中length=0
,而它应该是length=1
。
这意味着我无法编辑视频。 JavaScript 也无能为力。
问题是,当我静态地将有问题的网页(没有 Django,只是纯 HTML/JS/CSS)上传到我的网站进行测试时,它工作正常 - length=1
。
但是,如果我尝试在 Django 开发服务器上提供相同的静态页面,仍然会出现相同的问题。
我正在将 Django 的静态服务用于开发/调试目的 - 你会吗知道是什么原因造成的,或者我该如何解决它?
谢谢。
I've got a Django app serving a webpage with an HTML5 element. There's a wierd "feature", turning the video element to be non-seekable: video.seekable
returns a timeRanges
object with length=0
, whereas it should be length=1
.
This means I can't edit the video. JavaScript can't do anything either.
The thing is, when I upload the problematic webpage, statically - no Django, just plain HTML/JS/CSS - to my website for testing, it works fine - length=1
.
However, if I try to serve the same static page on my Django dev server still gives the same problem.
I am using Django's static serving for dev/debug purposes - Do you have any idea what is causing this, or how can I fix it?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Django 的开发服务器可能不支持 HTTP 字节范围,而浏览器通常使用 HTTP 字节范围来实现查找。
任何生产 Web 服务器,例如 Apache、lighttpd 或 nginx,都应该很好地支持这些。如果您可以在这些服务器之一上运行整个 Django 应用程序,那么问题就会消失。
一种解决方法是只从这样的服务器提供视频:将其中一个设置为在与 Django 开发服务器不同的端口上静态提供计算机上的视频目录,然后在您的开发环境中更改
Django's dev server probably doesn't support HTTP byte ranges, which is what browsers usually use to implement seeking.
Any production web server, e.g. Apache, lighttpd, or nginx, should support these fine. If you can run your entire Django app one of these servers the problem should go away.
A workaround would be to just serve the video from a server like that: set one of them up to statically serve the video directory on your machine on a different port than Django's dev server, and then in your dev environment either change the
<video src=
URL to point to the new web server, or write a special view for videos that redirects to the new web server.我遇到了同样的问题,并找到了一个简单的方法。
您可能想尝试以下操作:
在您的 wsgi.py 文件中:
有关更多信息:
点击此处
I was facing the same problem and found out an easy way around.
You may want to try this:
And in your wsgi.py file:
For more information:
Click Here
我自己没有遇到类似的事情,但我可以猜测,Django 开发服务器无法“像这样”传输视频。您可能需要使用 ETAG 中间件来解决这个问题。
看看这个问题:如何使用 Django 传输 HttpResponse
I didn't ran into anything like that myself, but I can guess, that Django development server can't stream a video "just like that". You might have to use ETAG middleware to cure this.
Take look at this question: How to stream an HttpResponse with Django
另请注意,当前的内置开发服务器是单线程的,因此可能很容易冻结。
并发测试服务器:https://github.com/jaylett/django_concurrent_test_server更适合流式传输/上传。 ..(在产品中不可用)
Also note the current builtin dev server is single-threaded so it may freeze easyly.
The concurrent test server : https://github.com/jaylett/django_concurrent_test_server is better for streaming/uploads... (not usable in prod)