Dave
Dave

Reputation: 187

What are the ways to allow embedded videos in Django/Python?

I'd like to allow embedded youtube videos (and other commonly embedded media) to be displayed using Django. Is there anyway in Django to allow this to happen?

The context is that I'm trying to display rss items, which may or may not have one or more embedded videos in a given item. Using the "safe" filter discards them, and writing a custom filter that returns mark_safe(html), where "html" is the passed through item, also discards them. Is there anyway to get past this?

Would you have to pull out the embedded objects from the rss items from within the view, and then re-embed them inside the template?

While I'm new to Django, I've done a fair amount of searching on this topic, and haven't found a useful answer yet. Any help would be much appreciated.

Upvotes: 3

Views: 692

Answers (3)

Peter
Peter

Reputation: 11

Use django-embed-video. It provides you all functionality you need.

Upvotes: 1

Dave
Dave

Reputation: 187

I figured out the answer to this question... I was using feedparser, which was removing certain content. I ended up adding a monkey patch (I believe this is the correct term) to allow more material make it through:

feedparser._HTMLSanitizer.acceptable_elements.add("object")
feedparser._HTMLSanitizer.acceptable_elements.add("embed")
feedparser._HTMLSanitizer.acceptable_elements.add("iframe")

Upvotes: 1

dbf
dbf

Reputation: 6499

  1. Parse youtuble links from RSS
  2. Pass them to template
  3. Use this http://djangosnippets.org/snippets/212/ template tag to convert links to embedding code

Upvotes: 0

Related Questions