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!

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

Yosef Fastow
Yosef Fastow
18,526 Points

How do you use a simple tag which needs a parameter in django?

In Conjagation Tag part 4 of 4:

Trying to add a simple tag conjugate_is in list.html but conjugate_is requires a parameter num which I want to be num_elf. I can't find out how to add the parameter so if anyone could help it would be appreciated!

(I know its easy to write conjugate_is as a filter and than use a pipe like {{ num_elf|conjugate_is }} but the code challenge requires conjugate_is to be a simple tag.)

from django import template

register = template.Library()

def conjugate_is(num):
    if num == 1:
        return 'is'
        return 'are'
{% load fairy_extras %}

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

[MOD: added "+jinja" to markdown formatting to make it pop! -cf]

1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 68,404 Points

You are very close. Don't use parens or tag notation surrounding num_elf. According to the docs, the argument is listed plainly following the simple_tag:

 {% conjugate_is num_elf %}
Seph Cordovano
Seph Cordovano
17,400 Points

+1 thank you. Was trying with the parenthesis for 20 mins lol