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_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%}
模板标签/video_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
推荐阅读
- c# - Xamarin Forms:Command 和 Event_Handler 无法为图像的旋转设置动画
- dart - 键盘弹出时出现白屏
- html - 这个通知“标识符'gridOptions'指的是componentAngular的私有成员”是否告诉我我没有遵循编码最佳实践?
- http - HTTP/HTTPS 代理
- excel-formula - 如何找到sr。没有在哪里主题等于1?例如,如果主题是印地语,则调用 Sr. No where field=1?
- office-js - 使用 Okta 的 Office-js-helpers OAuth2 身份验证?
- xaml - 使用带有 Prism 的 MVVM 在 Xamarin Forms 中旋转图像的最简单方法是什么
- sql - 创建存储过程。将数据从一个表插入到另一个表中。执行每个新条目
- python - 将 Django 与 MSSQL 错误链接:数据库驱动程序不支持现代数据时间类型
- django - 如何使用嵌套关系和包含嵌套关系的序列化程序来序列化字段?