None

Simple Django Filter

December 5, 2009

Here's the code required for a simple Django template filter. This is designed to a filter a user, and simply returns a link to the user profile.

Usage

<p>{{Object.owner|display_user}}</p>

Definition

from django import template
from django.utils.safestring import mark_safe

register = template.Library()

def display_user(pUser):
    """
    Output the HTML to link to a user
    """
    lString = 'Added by <a href="/users/%s/">%s</a>' % (pUser.username, pUser.username)
    return mark_safe(lString)

register.filter('display_user', display_user)