Using oEmbed in Django

oEmbed is a format, API to present links to multimedia websites like Flick or YouTube in a nice and content rich way. Easy and clean way to replace all links in a blog post or article to embedded players, or thumbs of linked images. You can look at for a list of popular websites supporting oEmbed.

Site that supports oEmbed provide URL that handles the API requests, like: It also has to provide information about which links are supported, for example:*. If we have those informations we can use the oEmbed API to get details about a link:
Which will return:
<author_name>Narayan Mukkavilli</author_name>

In Python we can use python-oembed or django-oembed. The Django application gives us ready to use set of template tags and database full of configs of sites supporting oEmbed.


To install django-oembed get the sources:
svn checkout django-oembed
And install it the standard way:
python install
In of your Django project add 'oembed' to INSTALLED_APPS and create tables for the application (syncdb). If the syncdb won't import django-oembed fixtures then copy oembed/fixtures/initial_data.json to project folder and execute:
python loaddata initial_data.json

The application is installed and ready to use.

In Django templates you can load the oembed tags by: {% load oembed_tags %} and use them on content:
{{ blog.content|oembed:"600x600" }}


{% oembed %}{{ blog.additional_content }}
{% endoembed %}
The parser used in those tags is bit odd and may not parse link if the content doesn't show a structure of a HTML document (some HTML tags before/after the link needed), When it will work the links will be nicely replaced, for example like this:

Django web framework tutorials, 8 August 2010

Comment article
Comment article RkBlog main page Search RSS Contact