问题描述
我正在尝试用我从其他地方获得的一些资源来提供我的 Django 页面.
I am trying to feed my Django page with some resource I am getting from somewhere else.
在提要中,我的 YouTube 视频的 URL 如下:https://www.youtube.com/watch?v=A6XUVjK9W4o
Inside the feed, I have YouTube videos with URL like: https://www.youtube.com/watch?v=A6XUVjK9W4o
一旦我将它添加到我的页面中,视频就不会显示,说:
Once I added this into my page, the video does not show up, saying:
拒绝显示'https://www.youtube.com/watch?v=A6XUVjK9W4o' 在一个框架,因为它将X-Frame-Options"设置为SAMEORIGIN".
Refused to display 'https://www.youtube.com/watch?v=A6XUVjK9W4o' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.
然后我说,好吧,如果我将 watch
更改为 embed
会怎样.然后YouTube播放器出现,但没有视频,说:
Then I said, well, what if I change watch
to embed
. Then YouTube player shows up, but no video, saying:
我怎样才能让它工作?
我在 HTML 中显示它是这样的:
I am showing it in HTML like this:
<iframe width="420" height="315"
src="{{vid.yt_url}}">
</iframe>
我用谷歌搜索了将近一个小时,但没有成功的迹象.我试图附加 &output=embed
- nada...
I googled almost for an hour, but no sign of success. I tried to append &output=embed
- nada...
推荐答案
您必须确保 URL 包含 embed 而不是 watch 作为 /embed
端点允许外部请求,而 /watch
端点不允许.
You must ensure the URL contains embed rather watch as the /embed
endpoint allows outside requests, whereas the /watch
endpoint does not.
<iframe width="420" height="315" src="https://www.youtube.com/embed/A6XUVjK9W4o" frameborder="0" allowfullscreen></iframe>
这篇关于嵌入 YouTube 视频 - 拒绝显示在框架中,因为它将“X-Frame-Options"设置为“SAMEORIGIN"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!