I want to use some custom filters, and so I am using the steps given
at
http://www.djangoproject.com/documentation/templates_python/#writing-custom-template-filters
What I did was,
1. Created a templatetags directory under th app and created
__init__.py, myfilters.py under it. Its structure is like,
app/
view.py
models.py
templatetags/myfilters.py
templatetags/__init__.py
2. added the app to installed app.
3. Wrote something like this to myfilters.py
from django.template.defaultfilters import stringfilter
from django.template import Variable, Library
register = Library()
@register.filter(name='captalise')
@stringfilter
def capitalise(val, args):
first, rest = val[0], val[1:]
return first.to_upper() + rest
I want to use this filter in the template, and am doing
{% load myfilters %}
hello {{foo}}
This gives me a
TemplateSyntaxError at /
'myfilters' is not a valid tag library: Could not load template
library from django.templatetags.myfilters, No module named myfilters
Stacktrace,
Traceback:
File "C:\Python24\lib\site-packages\django\core\handlers\base.py" in
get_response
73. callback, callback_args, callback_kwargs =
resolver.resolve(request.path)
File "C:\Python24\lib\site-packages\django\core\urlresolvers.py" in
resolve
233. sub_match = pattern.resolve(new_path)
File "C:\Python24\lib\site-packages\django\core\urlresolvers.py" in
resolve
172. return self.callback, args, kwargs
File "C:\Python24\lib\site-packages\django\core\urlresolvers.py" in
_get_callback
184. raise ViewDoesNotExist, "Tried %s in module %s.
Error was: %s" % (func_name, mod_name, str(e))
What am I missing?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---