Sorry for my mistake, I wrote 'a' to test the code, if it's wrong I hope it will report a error.
The corrected is here: <div><a href="#">{{ people.name|cut_by_string:"10" }}</a></div> I run the code in the shell, it report right result to me, but I don't know why it's not apply effect in the web page. $ ./manage.py shell Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from addressbook.core.templatetags.extra_filters import cut_by_string >>> cut_by_string("Hello World", 3) u'Hel...' >>> cut_by_string("Hello World", 11) u'Hello World...' On Nov 19, 6:09 pm, Daniel Roseman <[EMAIL PROTECTED]> wrote: > On Nov 19, 9:52 am, "K*K" <[EMAIL PROTECTED]> wrote: > > > > > Hi, All. > > > I create a custom filter for cut too long string for my app. > > > Like this: > > > from django import template > > from django.template.defaultfilters import stringfilter > > > register = template.Library() > > > @register.filter(name='cut_by_string') > > @stringfilter > > def cut_by_string(value, arg): > > if len(value) < arg: > > return value > > else: > > return value[:arg-3] + "..." > > > And in the template I load the filter .py normally, and set below > > codes: > > > <div><a href="#">{{ testplan.name|cut_by_string:"a" }}</a></div> > > > But it doesn't work, do I make any mistake in this code ? > > I'm not quite sure what the filter is supposed to do, but you're > passing a string and then checking if its length is 'less than' > another string. This doesn't make sense. This line would seem to be > the problem: > if len(value) < arg: > According to the values you've passed, this evaluates to: > if len('string') < 'a': > which will always be true. > > I wonder if you meant > if len(value) < len(arg) > ?? > > -- > DR. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---