Hello,
Just had this same problem myself, and found the solution -- you need
to do the following:
- create a templatetags directory INSIDE one of what Django calls your
'installed apps.' Apps are modules directly under your project root,
for example, if your project has an app named home, your directory
structure should look like:
project/
home/
templatetags/
- Create an empty __init__.py in the templatetags directory.
- In the templatetags folder, create another file for your filter,
e.g., my_awesome_filter.py
You have, now:
project/
home/
templatetags/
__init__.py
my_awesome_filter.py
Now, at this point, tutorials leave the expectation that {% load
my_awesome_filter %} should just work, but there's one little piece of
magic they leave out: you have to add your app to Django's list of
INSTALLED_APPS so that the template tag loader can find it. Edit
settings.py, add an entry to the INSTALLED_APPS tuple as follows
(excerpted from my live app, yours will differ):
INSTALLED_APPS = (
'appengine_django', # Use the App Engine helper
'django.contrib.auth', # Load up the Django auth system
(optional, but I like it)
'home' # <-- Added
)
Worked like a charm for me.
best,
- Fred.
On Sep 3, 6:28 am, joune <
jounepan...@gmail.com> wrote:
> Hi there,
>
> just meant to say that i have the very same problem..
> i followed django documentation to create a custom filter in
> my_utils.py that i put under a templatetags directory under my app and
> along with an empty __init__.py file
> the {%loadmy_utils.py %} tag throws the same
> TemplateSyntaxError: 'my_utils' is not a valid tag library
>
> i came to wonder if there was a limitation on custom filters in google
> appEngine.. (but it seems to work for g-man)
> i based my code on this sample:
http://google-app-engine-samples.googlecode.com/files/django_example_...
> and didn't change anything to settings.py (maybe i should have?)
>
> any input no this would be very helpful!
>
> thanks..
>
> On Aug 1, 12:11 pm, Arun Shanker Prasad <
ArunShankerPra...@gmail.com>
> wrote:
>
> > Hi,
> > @g-man ,
>
> > I am also not using the webapp with google app engine,
> > but when I try toloadthe filter in the template an exception is
> > raised
>
> > 'customfilters' is not a valid tag library: Could notloadtemplate
> > library from django.templatetags.customfilters, No module named
> > customfilters
>
> > My Code:
> > import django
> > from django import template
>
> > register = template.Library()
>
> > @register.filter('modulo')
> > def modulo(value, arg):
> > if value % arg == 0:
> > return True
> > else:
> > return False
>
> > In Template
> > {%loadcustomfilters %}
>
> > Am i missing something? any help will be appricicated
>
> > On Jul 22, 8:19 am, g-man <
gregor...@gmail.com> wrote:
>
> > > I, for one, appreciate your keeping all of us up-to-date on your
> > > explorations and discoveries, Larry!
>
> > > As a companion piece, here's my Djangotemplate tagthat creates a