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 ?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to