from django import template
from django.contrib.auth.models import Group
register = template.Library()

@register.filter(name='has_group')
def has_group(user, group_name):
    pass
How to check (in template) whether user belongs to group