1

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

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

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

<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 可能有问题。它被定义为:

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

1 回答 1

2

您应该{{ MEDIA_URL }}在模板中使用您在 settings.py 中定义的标签。

settings.py 中的示例:

MEDIA_URL = '/media/'

MEDIA_ROOT 和 STATIC_ROOT 一样,是Django 用来上传媒体文件和提供媒体文件的目录,而不是 URL 路径

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

于 2013-04-22T18:45:48.997 回答