On Mon, 2007-11-05 at 05:02 -0800, [EMAIL PROTECTED] wrote: > here is my filter: > from django import template > import datetime > > register = template.Library() > > @register.filter > def mytimeiff(timestamp = None):
Typo here. Almost certainly should be "mytimediff" -- you left out the 'd'. The error message you are seeing is a sure sign that there's a spelling error somewhere, so this is the first sort of thing to look for. > """ > Returns a humanized string representing time difference > between now() and the input timestamp. > > The output rounds up to days, hours, minutes, or seconds. > 4 days 5 hours returns '4 days' > 0 days 4 hours 3 minutes returns '4 hours', etc... > """ > > timeDiff = datetime.datetime.now() - timestamp > days = timeDiff.days > hours = timeDiff.seconds/3600 > minutes = timeDiff.seconds%3600/60 > seconds = timeDiff.seconds%3600%60 > > str = "" > tStr = "" > if days > 0: > if days == 1: tStr = "day" > else: tStr = "days" > str = str + "%s %s" %(days, tStr) > return str > elif hours > 0: > if hours == 1: tStr = "hour" > else: tStr = "hours" > str = str + "%s %s" %(hours, tStr) > return str > elif minutes > 0: > if minutes == 1:tStr = "分钟" > else: tStr = "分钟" Unrelated to your original question, but either you have a line like # coding: utf-8 as the first or second line of your file, or these lines (using non-ASCII characters) are might be a cause of problems down the track. > str = str + "%s %s" %(minutes, tStr) > return str > elif seconds > 0: > if seconds == 1:tStr = "秒" > else: tStr = "秒" > str = str + "%s %s" %(seconds, tStr) > return str > else: > return None > > and i use it in the templates as below: > > {% load mytimediff %} > {{ s.time|mytimediff }} > > got this error: > Exception Type: TemplateSyntaxError > Exception Value: Invalid filter: 'mytimediff' > > can somebody help me out, thanks! Regards, Malcolm -- How many of you believe in telekinesis? Raise my hand... http://www.pointy-stick.com/blog/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---