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 Chaining Filters

Best practices for naming filters

I notice the built-in filters are written as one word, ie 'wordcount', 'linebreaks' etc, but the one we made was written using an underscore; 'time_estimate'

Is one style preferred over the other?

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

Great question. There doesn't seem to be a hard rule. The list of built-in filters appear to be mostly single word with no underscores. The ones with underscores seem to fall into two camps:

  • filters that are extensions of other filters: truncatewords v. truncatewords_html
  • filters that have a verb /noun combination: make_list, get_digit

But why truncatewords isn't truncate_words breaks the pattern. Maybe to avoid a double underscore for truncate_words_html. So both time_estimate and timeestimate work. Perhaps it depends on which you find more readable.

Awesome thanks a lot for clearing that up!