python - custom template tag with multiple arguments -
i want format date in future based on time delta:
from django import template datetime import datetime, timedelta, time register = template.library() @register.simple_tag def tomorrow(format): tommorow = datetime.now() + timedelta(days=1) return tommorow.strftime(format) def dayfuture(dday, format): dayfuture = datetime.now() + timedelta(days=dday) return dayfuture.strftime(format)
this works:
{% tomorrow "%a, %d %b, %y" %}
but i've had no luck dayfuture
.
also, possible have multiple custom template tags in same file. i've had no luck registering second one.
i'm using django 1.11 pythone 3.4
this not work because did not register it. possible have multiple template tags inside single file.
def dayfuture(dday, format): dayfuture = datetime.now() + timedelta(days=dday) return dayfuture.strftime(format)
you have put decorator on register it
@register.simple_tag def dayfuture(dday, format): dayfuture = datetime.now() + timedelta(days=dday) return dayfuture.strftime(format)
wiki
Comments
Post a Comment