Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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 67,989 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