truncatechars from start + slice from end

Is there a better way to do this ?

<a href="{{ url }}">
    {{ url|truncatechars:20 }}...{{ url|slice:"-20:" }}
</a>

Do it in the view and pass it as a separate value in the context?

Create a custom filter?

I tried to create a custom filter but always returned

return parser.libraries[name]
KeyError: 'custom_filters'

My templates are not in the app and I have 5 apps where I want the custom_filters to be accessed from any of the apps.

Custom tags and filters are not specific to any app. They are available anywhere in the project.

See How to create custom template tags and filters | Django documentation | Django