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 Reverse Text Filter

django template

Challenge Task 1 of 2

Create a function called "reverse_text" that takes a string as an argument, and returns a string with those words reversed. So reverse_text("balloon") should return "noollab".

code_challenges/templatetags/extras.py
from django import template

register = template.Library()


def reverse_text("balloon"):
    return "balloon"[::-1]

I tried the above , but the code is not working, I am not sure whats wrong with the code.

1 Answer

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Wisdom,

You can't define a function like that - it needs to take arguments that are variables, not string literals.

The idea is to create a function that takes any string and reverses it. You've created an example that reverses "balloon" only. Replace that string literal with a variable (call it word, or string, or whatever you want), and this should pass. Then you can call your function like this:

reverse_text("I can put whatever text I want in here!")