为django提供/消费富媒体
项目描述
安装
首先,您需要安装OEmbed。它可在http://github.com/worldcompany/djangoembed/找到
git clone git://github.com/worldcompany/djangoembed/ cd djangoembed python setup.py install
添加到您的Django项目
安装后,将OEmbed消费添加到您的项目中非常简单。首先,将其添加到项目的INSTALLED_APPs中并运行'syncdb'
# settings.py
INSTALLED_APPS = [
...
'oembed'
]
djangoembed使用与admin相似的注册模式。为了确保所有应用程序都已加载,djangoembed应在urls.py中运行autodiscover()。如果您喜欢,可以将此代码放置在admin.autodiscover()部分下方
# urls.py import oembed oembed.autodiscover()
消费资源
现在您已准备好开始消费可嵌入的OEmbed对象。根据您想要做什么,有几个选项。开始运行的最直接方法是将其添加到模板中
{% load oembed_tags %}
{% oembed %}blog.content{% endoembed %}
{# or use the filter #}
{{ blog.content|oembed }}
{# maybe you're working with some dimensional constraints #}
{% oembed "600x600" %}blog.content{% endoembed %}
{{ blog.content|oembed:"600x600" }}
您也可以在Python中使用oembed对象
import oembed
oembed.autodiscover()
# just get the metadata
resource = oembed.site.embed('http://www.youtube.com/watch?v=nda_OSWeyn8')
resource.get_data()
{u'author_name': u'botmib',
u'author_url': u'http://www.youtube.com/user/botmib',
u'height': 313,
u'html': u'<object width="384" height="313"><param name="movie" value="http://www.youtube.com/v/nda_OSWeyn8&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/nda_OSWeyn8&fs=1" type="application/x-shockwave-flash" width="384" height="313" allowscriptaccess="always" allowfullscreen="true"></embed></object>',
u'provider_name': u'YouTube',
u'provider_url': u'http://www.youtube.com/',
u'title': u'Leprechaun in Mobile, Alabama',
u'type': u'video',
u'version': u'1.0',
u'width': 384}
# get the metadata and run it through a template for pretty presentation
from oembed.consumer import OEmbedConsumer
client = OEmbedConsumer()
embedded = client.parse_text("http://www.youtube.com/watch?v=nda_OSWeyn8")
<div class="oembed oembed-video provider-youtube">
<object width="384" height="313">
<param name="movie" value="http://www.youtube.com/v/nda_OSWeyn8&fs=1"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/nda_OSWeyn8&fs=1"
type="application/x-shockwave-flash"
width="384"
height="313"
allowscriptaccess="always"
allowfullscreen="true">
</embed>
</object>
<p class="credit">
<a href="http://www.youtube.com/watch?v=nda_OSWeyn8">Leprechaun in Mobile, Alabama</a>
by
<a href="http://www.youtube.com/user/botmib">botmib</a>
</p>
</div>'
故障排除
问题:您尝试youtube嵌入示例,但您得到的是youtube视频的链接。
解决方案:djangoembed使用固件将有关oembed提供者(如Youtube)的数据加载到数据库中。尝试使用syncdb(或如果您正在运行South,则使用迁移)进行调整,直到有oembed.storedprovider类型的对象。
如果您还有其他问题,请考虑查阅项目doc子目录中的更详细文档。
项目详情
关闭
djangoembed-0.1.1.tar.gz的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | e647ad841674642ddfc27ec2d5a98a76c41bd22b5adc7f07c2d7773b3bc7287c |
|
| MD5 | 046b1cbe83094bd6ef05f9e90fe80568 |
|
| BLAKE2b-256 | b8e6101ca966c401db8b0722a859d4e07cdfbe99c3adaddc62722577159cd250 |