Custom Search

Wednesday, March 10, 2010

how to django template simple tag

how to django template simple tag

----------------- in template

{% can_edit_comment comment.created_on %} <--- Important: it directly print return value.

----------------- in /templatetags/siren.py

from django import template
register = template.Library()

@register.simple_tag
def can_edit_comment(created_on):
print "created_on",created_on
print "edit time", created_on + datetime.timedelta(minutes=35)

edit_time = created_on + datetime.timedelta(minutes=35)

print "today", datetime.datetime.today()

if edit_time > datetime.datetime.today():
print "can edit"
return True
else:
print "not edit"
return False


----------------------

No comments:

Post a Comment