OEmbed任何内容。
项目描述
feincms-oembed 通过让Embedly或另一个OEmbed提供者进行艰苦的工作,将来自200多个内容提供商的标准URL转换为嵌入视频、图片和丰富文章预览。
使用非常简单
将'feincms_oembed'添加到INSTALLED_APPS。
创建内容类型
from feincms.module.page.models import Page from feincms_oembed.contents import OembedContent TYPE_CHOICES = [ ('default', _('Default presentation'), { 'maxwidth': 500, 'maxheight': 300, 'wmode': 'opaque'}), ('transparent', _('Transparent'), { 'maxwidth': 500, 'maxheight': 300, 'wmode': 'transparent'}), ] Page.create_content_type(OembedContent, TYPE_CHOICES=TYPE_CHOICES)
您还可以指定发送给OEmbed提供者的其他参数
Page.create_content_type(OembedContent, TYPE_CHOICES=TYPE_CHOICES, PARAMS={'wmode': 'opaque'})
默认情况下,feincms_oembed使用Embedly Oembed提供者。即使对于免费计划,此提供者也需要API密钥。因此,必须设置settings.EMBEDLY_KEY。免费计划每月适用于5000个URL。
如果您想自定义Embedly请求或使用另一个OEmbed提供者,请将settings.OEMBED_PROVIDER设置为接收URL和包含附加参数的字典的函数,并返回在访问时返回OEmbed JSON的适当URL。 OEMBED_PROVIDER必须是点分Python路径或可调用对象
from feincms_oembed.providers import embedly_oembed_provider def my_provider(url, kwargs): kwargs['wmode'] = 'opaque' return embedly_oembed_provider(url, kwargs) OEMBED_PROVIDER = 'path.to.module.my_provider' # OEMBED_PROVIDER = my_provider # The function can be used too, not only # the dotted python path.
内容将在以下顺序在文件夹content/external/中查找模板
嵌入对象的类型(例如,“视频”)+ .html
内容类型类型(例如“透明”)+ .html
default.html
如果您不想在访问Embedly时遇到任何惊喜,建议您注册一个免费的API密钥。注册。
使用FeedContent
如果您想使用FeedContent,请确保您在Python路径中已安装feedparser。