@register.assignment_tag(takes_context=True)
def render_template_for(context, obj, template=None, template_directory=None):
 context['object'] = obj
 template_list = []
 if template:
  template_list.append(template)
 template_dirs = []
 if template_directory:
  template_dirs.append(template_directory)
 template_dirs.append('community/types')
 for directory in template_dirs:
  template_list.append('{}/{}.html'.format(directory, obj.get_media_type_display()))
  template_list.append('{}/default.html'.format(directory))
 output = render_to_string(template_list, context)
 return output

@ register . assignment_tag ( takes_context = True ) def render_template_for ( context , obj , template = None , template_directory = None ) : context [ 'object' ] = obj template_list = [ ] if template : template_list . append ( template ) template_dirs = [ ] if template_directory : template_dirs . append ( template_directory ) template_dirs . append ( 'community/types' ) for directory in template_dirs : template_list . append ( '{}/{}.html' . format ( directory , obj . get_media_type_display ( ) ) ) template_list . append ( '{}/default.html' . format ( directory ) ) output = render_to_string ( template_list , context ) return output
renders a template based on the media_type of the given object in the given template directory .