Django-使用jwplayer显示视频 [英] Django - Displaying video with jwplayer

查看:228
本文介绍了Django-使用jwplayer显示视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用jwplayer在网站上显示视频.该页面的视图是

I am currently trying to display a video on a website using jwplayer. The view for the page is

def video(request):
        return render_to_response('video_player/video.html', context_instance=RequestContext(request)

正在使用的html模板的头部包含以下内容:

And the html template being used contains this in the head:

<script type="text/javascript" src="/jwplayer/jwplayer.js"></script>

这在体内:

<div id="myElement">Loading the player...</div>
<script type="text/javascript">
    jwplayer("myElement").setup({
        file: "{{ MEDIA }}videos/test.mp4",
        image: "{{ MEDIA }}videos/cute-bunny.jpg"
    });
</script>

除了显示正在加载播放器"外,它什么都不显示,我认为调用media_root可能有问题.定义为:

It doesn't display anything other than 'Loading the player', i think there may be something wrong with me calling the media_root. It is defined as:

MEDIA_ROOT = 'C:/Users/Timmy/Documents/GitHub/GroupProject/media'

推荐答案

您应该在模板中使用{{ MEDIA_URL }}标记,该标记是在settings.py中定义的.

You should be using the {{ MEDIA_URL }} tag in your templates, which you define in settings.py.

settings.py中的示例:

Example in settings.py:

MEDIA_URL = '/media/'

MEDIA_ROOT与STATIC_ROOT一样,是Django用于将媒体文件上传到其中并从中提供媒体文件的目录,而不是URL路径.

MEDIA_ROOT, like STATIC_ROOT, is the directory that Django uses to upload media files to and serve media files from, not the URL path.

请参阅: https ://docs.djangoproject.com/en/dev/howto/static-files/#serving-files-uploaded-by-a-user

这篇关于Django-使用jwplayer显示视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆