from django import template from django.template.loader import get_template, TemplateDoesNotExist register = template.Library() @register.filter def render_search_result(result): """ Renders a search result. {% if page.object_list %} {% for result in page.object_list %}
No results found.
{% endif %} """ app_label = result.content_type().split('.')[0] model_label = result.content_type().split('.')[1] try: t = get_template("search/result/%s/%s.html" % (app_label, model_label)) except TemplateDoesNotExist: t = get_template("search/result/default.html") return t.render(template.Context({ 'object': result.object, }))