1from django.template.loader import render_to_string 2 3from wagtail.embeds import embeds 4from wagtail.embeds.exceptions import EmbedException 5 6 7def embed_to_frontend_html(url, max_width=None, max_height=None): 8 try: 9 embed = embeds.get_embed(url, max_width, max_height) 10 11 # Render template 12 return render_to_string('wagtailembeds/embed_frontend.html', { 13 'embed': embed, 14 }) 15 except EmbedException: 16 # silently ignore failed embeds, rather than letting them crash the page 17 return '' 18 19 20def embed_to_editor_html(url): 21 embed = embeds.get_embed(url) 22 # catching EmbedException is the responsibility of the caller 23 24 # Render template 25 return render_to_string('wagtailembeds/embed_editor.html', { 26 'embed': embed, 27 }) 28