@register.tag(name='get_latest_annotations')
def do_get_latest_annotations(parser, token):
    as_var = None
    count = 1
    try:
        contents = token.split_contents()
        if len(contents) >= 2 and contents[1] == "as":
            as_var = contents[2]
        if len(contents) == 4:
            count = int(contents[3])
    except (ValueError, IndexError):
        raise template.TemplateSyntaxError, "Tag Syntax Error: %r as annotations [count=1]" % token.contents.split()[0]
    return LatestAnnotationsNode(as_var, count)
Use like so: {% get_latest_annotations as annotations [count=1]%}
dataset/ETHPy150Open stefanw/django-annotatetext/annotatetext/templatetags/annotatetags.py/do_get_latest_annotations