David542
David542

Reputation: 110382

Template Filter crashing

I have a template filter that I am loading in my template.

The template is in:

- userprofile/
  - templatetags/
    - __init__.py
    - extras.py

Userprofile is in my installed apps and it seems to be importing extras correctly.

My template tag in extras.py is:

register = template.Library()

@register.filter
def minutes_seconds(seconds):
    """
    Format a time in seconds in the MM:SS form.
    """
    return '{:02}:{:02}'.format(int(seconds) / 60, int(seconds) % 60)

And in my django template I am doing:

{% extends 'base.html' %}
{% load extras %}
...
{{ items|minutes_seconds }}

But this blows up, and I get a TemplateSyntaxError: Invalid Filter. It seems to be a very low level error, because I can cause other errors in the template (for example, removing a {% for %} tag so it would otherwise raise an error), but it seems to be triggering this TempalteSyntaxError almost before the page is even rendered. What is going wrong here?

Upvotes: 1

Views: 224

Answers (1)

Zubair Afzal
Zubair Afzal

Reputation: 2086

Check the dir "userprofile/templatetags/", are there compiled python files for init.py and extras.py?

If there are no compiled files in there then it means that templatetags dir is not being accessed by python. Make sure init.py file is there in that dir then restart the server and again check for .pyc files.

Upvotes: 3

Related Questions