python - Render Image on a template from a json string [Wagtail CMS] -


i have below output:

{'type': 'lead-image', 'value': {'id': 123, 'alt': 'a fish', 'format': 'full-width'}} 

i want display specific image on html template, how go it?

the expand_db_attributes method on wagtail.wagtailimages.rich_text.imageembedhandler translation you're looking for. packaged template tag (please adjust appropriate own use-case - looks you've got python dict there, rather json string):

import json django.utils.html import escape wagtail.wagtailimages.rich_text import imageembedhandler   register = template.library()  @register.simple_tag def json_to_image(json_string):     data = json.loads(json_string)      # expand_db_attributes expects receive html-escaped attributes,     # explicitly escape alt attribute here (assuming it's not     # escaped in json)     data['value']['alt'] = escape(data['value']['alt'])      return imageembedhandler.expand_db_attributes(data['value'], false) 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -