0

我的 HTML 页面如下所示:

 <div>
    <iframe margin="0" padding="0" border="none" width="420" height="345" frameBorder="0"
      ng-src="{{exercise_video_url}}">
    </iframe>  
  </div>

'exercise_video_url' 我在我的控制器中设置如下:

$http.get("https://localhost:8000/api/exercises/initial/").then(function(response){

  $scope.initial_data=response.data;

  angular.forEach($scope.initial_data, function(item){

               $scope.exercise_type=item.exercise_type;
               $scope.exercise_description=item.description;
               $scope.exercise_video_url=$sce.trustAsResourceUrl(item.video_url);
})

我正在从我的 Django 视图中获取特定的运动相关信息,运动模型有一个 video_url 作为属性。我在某处阅读并在我的角度控制器中注入了 $sce 服务。

视频链接本身看起来像' https://youtu.be/ ******' --> * 是几个随机字符。如果您在浏览器中点击此链接或直接将其作为 ng-src 的来源,则此链接可以独立工作。

我还尝试在我的 settings.py 中 评论“ django.middleware.clickjacking.XFrameOptionsMiddleware ”

4

1 回答 1

0

它是您使用的 YouTube 网址,它需要是嵌入版本。我刚刚在我的网站上修复了类似的问题并开始工作。

由于您将其嵌入到 iframe 中,因此只能使用 YouTube 嵌入网址。

所以示例不要使用短 url 嵌入 iframe,使用嵌入 url。

错误的: <iframe width="1260" height="709" src="<iframe width="1260" height="709" src="https://www.youtube.com/watch?v=xWRNBOXoLf8" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>

正确的: <iframe width="1260" height="709" src="<iframe width="1260" height="709" src="https://www.youtube.com/embed/xWRNBOXoLf8?ecver=1" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>

利用https://www.youtube.com/embed/xWRNBOXoLf8?ecver=1

于 2018-08-17T12:19:00.770 回答