@register.filter
def rest_json(value, arg=None):
 if (not value):
  return mark_safe(u'{}')
 if (not isinstance(value, (dict, OrderedDict, list, tuple))):
  msg = u'Given value must be of type dict, OrderedDict, list or tuple but it is {}.'
  raise ValueError(msg.format(value.__class__.__name__))
 data = JSONRenderer().render(value)
 return mark_safe(data)

@ register . filter def rest_json ( value , arg = None ) : if ( not value ) : return mark_safe ( u'{}' ) if ( not isinstance ( value , ( dict , OrderedDict , list , tuple ) ) ) : msg = u'Given value must be of type dict, OrderedDict, list or tuple but it is {}.' raise ValueError ( msg . format ( value . __class__ . __name__ ) ) data = JSONRenderer ( ) . render ( value ) return mark_safe ( data )
renders a returndict as used by the rest framework into a safe json string .