I definitely doing something wrong but I’m not sure what!
In my django project, I created a folder called “templatetags”, in that folder I have:
__init__.py
tags.py
In tags.py:
from datetime import datetime
from django import template
register = template.Library()
@register.filter("timestamp")
def timestamp(value):
try:
return datetime.fromtimestamp(value)
except AttributeError:
return ''
In one of my templates I call:
{{record.date|timestamp|date:"D d M Y"}}
Yet when I run the template I get the following output error:
Exception Type: TemplateSyntaxError
Exception Value:
Invalid filter: 'timestamp'
Can someone let me know what I”m doing wrong?
2 things to check
1. Is your app listed in INSTALLED_APPS
2. did you load the custom tag in the file? i.e
{% load tags %}