aero
aero

Reputation: 1724

Django: Template isn't loading app_tags file. Unable to use custom filter: "Invalid Filter"

I have the following folder structure:

myProject
        |
       myapp
           |
          templatetags
                     | __init__.py
                     | app_tags.py

The app_tags.py file:

from django import template
from django.template.defaultfilters import stringfilter

register = template.Library()

@register.filter(is_safe=False)
@stringfilter
def upper2(value):
    """Converts a string into all uppercase."""
    return value.upper()

The test.html template:

{% load app_tags % }

<div>Test Word: {{ test_word }}</div>
<div>Test Word: {{ test_word|upper2 }}</div>

If I use the {{ test_word|upper2 }} I get an Invalid filter: 'upper2' error.

enter image description here

If I don't try to use the upper2 filter, the {% load app_tags % } doesn't appear to be loading.

enter image description here

Thanks for any help!

Upvotes: 0

Views: 386

Answers (1)

aero
aero

Reputation: 1724

And... there was a white space in {% load app_tags % }

Once I changed the loading tag to {% load app_tags %}, it worked great!

Upvotes: 1

Related Questions