调整鹡鸰嵌入视频的大小

问题描述 投票:0回答:1

你好,我是新来的wagtail。最初,我看到,我们能够方便地嵌入视频通过draftail,但我无法给它任何风格。因此,我交换了方法,到目前为止,我一直在使用以下实现嵌入视频到我的项目。

块.py

class VideoBlock(blocks.StreamBlock):
'''rich text'''
title = blocks.CharBlock(required=True, help_text="Add your Title")
texts = blocks.TextBlock(required=True, help_text="Add your additional text")
embed = EmbedBlock()

class Meta:
    template = "streams/video_block.html"
    icon = "edit"
    label = "Full Rich Text

video_block.html

{% load wagtailembeds_tags %}


{%for content in self %}
    <div class="container" style="text-align: center;">
    {{content}}
    {% embed page.video_url %}
    </div>
{%endfor%}

这就是说,我仍然不知道如何正确地调整它的大小。我最好是希望我的网站看起来像这样。这里

video embedded wagtail
1个回答
1
投票

我发现了一个非常好的链接在她。这里

如果有人对我的代码感兴趣,请看我的代码。

video_block.html

{% load wagtailembeds_tags %}
{% load video_tag%}
<br>
{%for content in self %}
    <div class="container">
        {%for con in content.value%}
        <h1>{{con.title}}</h1>
        <p>{{con.text}}</p>
        <div class="embed-responsive embed-responsive-16by9">
            <iframe class="embed-responsive-item" src="{{ con.video.url |embedurl}}?rel=0" allowfullscreen></iframe>
          </div>
        {%endfor%}
    </div>
{%endfor%}

templatetagsvideo_tag.py。

import re
from django import template

register = template.Library()

@register.filter(name="embedurl")
def get_embed_url_with_parameters(url):
    print('we inside this emb')
    if "youtube.com" in url or "youtu.be" in url:
        regex = r"(?:https:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(.+)"  # Get video id from URL
        embed_url = re.sub(
            regex, r"https://www.youtube.com/embed/\1", url
        )  # Append video id to desired URL
        print(embed_url)
        embed_url_with_parameters = embed_url + "?rel=0"  # Add additional parameters
        return embed_url_with_parameters
    else:
        return None
© www.soinside.com 2019 - 2024. All rights reserved.