3π
β
If youβre worried about typos, missing __init__.py
problems or masked ImportError
s, 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'
π€supervacuo
6π
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.
π€dani herrera
- [Django]-Thumbnails in the django admin panel using sorl
- [Django]-Django reverse function arguments
- [Django]-Spam proof hit counter in Django
Source:stackexchange.com