Hello hello,
I have a custom template filter that works perfectly under django 3.2.18
.
When switching to django 4.1.7
, I get :
django.template.exceptions.TemplateSyntaxError: Invalid filter: 'daysuntil'
Simplified version:
from django import template
from django.utils import timezone
register = template.Library()
@register.filter(name='daysuntil')
def daysuntil(d, now=timezone.now()):
return 1
folder structure:
portal
|__ portal_core
|__ templatetags
|__ __init__.py
|__ daysuntil.py
|__ __init__.py
settings:
INSTALLED_APPS += (
<snip>
'portal.portal_core',
)
just switching the django version causes it to break.
Any idea? something I missed in the release notes? :[
EDIT (template) =============
Exception when template is used/loaded/requested:
<snip>
File "/env/lib/python3.11/site-packages/django/template/base.py", line 154, in __init__
self.nodelist = self.compile_nodelist()
^^^^^^^^^^^^^^^^^^^^^^^
File "/env/lib/python3.11/site-packages/django/template/base.py", line 200, in compile_nodelist
return parser.parse()
^^^^^^^^^^^^^^
File "/env/lib/python3.11/site-packages/django/template/base.py", line 484, in parse
raise self.error(token, e)
File "/env/lib/python3.11/site-packages/django/template/base.py", line 482, in parse
filter_expression = self.compile_filter(token.contents)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/env/lib/python3.11/site-packages/django/template/base.py", line 600, in compile_filter
return FilterExpression(token, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/env/lib/python3.11/site-packages/django/template/base.py", line 698, in __init__
filter_func = parser.find_filter(filter_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/env/lib/python3.11/site-packages/django/template/base.py", line 606, in find_filter
raise TemplateSyntaxError("Invalid filter: '%s'" % filter_name)
django.template.exceptions.TemplateSyntaxError: Invalid filter: 'daysuntil'
Template:
{% load static media daysuntil %}
<snip>
{{ object.event_datetime|daysuntil }}
</snip>