Search code examples
djangoiframeyoutubex-frame-options

Problem embedding youtube video's with with django template


I have a django template that displays a list of objects with youtube videos:

{% for obj in objs %}
    <h1>{{ obj.name }}</h1>
    <iframe width="425" height="349" src="{{ obj.video}}" frameborder="0" allowfullscreen=""></iframe>
{% endfor %}

obj.video is stord as a urlField. When I load the page chrome console gives me the error refused to display document because display forbidden by x-frame-options.

The problem persists if I replace {{ obj.video }} with a manually written youtube embed url such as http://youtu.be/zzfQwXEqYaI. However, if I replace it with something like www.google.com the iframes will load.


Solution

  • Try embedding the video like with url like:

    http://www.youtube.com/embed/zzfQwXEqYaI
    

    I guess its some kind of protection from youtube