Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Customizing Django Templates Building Custom Filters Conjugation Tag

SUVODEEP DUBEY
SUVODEEP DUBEY
2,470 Points

Template Tag Not Working

Please find the code below I am getting an error

code_challenges/templatetags/fairy_extras.py
from django import template

register = template.Library()

@register.simple_tag
def conjugate_is(elf_count):
    '''Return conjugated verb 'to be' on singular or plural elf counts'''
    if elf_count==1:
        return "is"
    else:
        if elf_count!=1:
            return "are"
code_challenges/templates/code_challenges/list.html
{% load fairy_extras %}

There {{ num_elf|conjugate_is }} {{ num_elf }} el{{ num_elf|pluralize:"f,ves" }}.

1 Answer

I realize that this is an older post but the reason your template tag isn't working is because you need to remove the

{{ num_elf | conjugate_is }}.

That is for filtering. When wanting to use a simple tag and pass data into it you need to use the form

{% my_tag_function variable_to_pass_in %}