Django - Displaying video with jwplayer

怎甘沉沦 提交于 2019-12-11 13:26:19

问题


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)

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

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

And this in the body:

<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>

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'

回答1:


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

Example in settings.py:

MEDIA_URL = '/media/'

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.

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



来源:https://stackoverflow.com/questions/16152380/django-displaying-video-with-jwplayer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!