¿Cuáles son las formas de permitir videos incrustados en 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.

preguntado el 04 de julio de 12 a las 05:07

This doesn't appear to be anything specific to django. Seems to be purely related to the client side html+javascript solution. If your question is specifically about to how parse the rss, then you need to provide examples. -

It's not client side. I'll pulling rss feeds, and passing the items (specifically the "description" or "content" portion) from the view to the template, and the template removes all embeds. I think what dbf wrote below is correct, but I was hoping there was an easier way to pass it from the view to template without having to separate the content into embeds and non-embeds. -

3 Respuestas

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")

Respondido 11 Abr '13, 05:04

Utiliza django-incrustar-video. It provides you all functionality you need.

Respondido el 01 de diciembre de 13 a las 11:12

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

Respondido 04 Jul 12, 06:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.