How can I import a custom template tag or filter in the interactive shell to see if the everything is working fine?
I have two machines behaving differently and I don't have a clue of how to do some debugging.
On the production machine I can't load a template filter, I get the error "Template library not found". On the local machine everything works fine.
Importing filters like this:
from django.template import defaultfilters as filters
filters.date( date.today() )
Instead default filters you should import your custom filter:
from myApp.templatetags import poll_extras
poll_extras.cut( 'ello' )
Double check settings installed app in your production server.
If you're worried about typos, missing __init__.py problems or masked ImportErrors, you could just import the function. Assuming the following structure:
foo
├── bar
│ ├── __init__.py
│ ├── models.py
│ ├── static
│ │ └── ..
│ ├── templates
│ │ └── ..
│ ├── templatetags
│ │ ├── __init__.py
│ │ └── baz.py
│ ├── views.py
├── manage.py
└── foo
├── __init__.py
├── settings.py
├── urls.py
└── wsgi.py
and the following contents of baz.py:
from django import template
register = template.Library()
@register.filter
def capitalize(value):
return value.capitalize()
you would just run
>>> from bar.templatetags import baz
>>> print baz.capitalize('test')
'test'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With