开发者

Check if a date is in the future

How can I check from within a Django template whether a given date is in the future?

Something like:

{% if event.dat开发者_如何学Pythone > now %}


Write a function on event named in_future, that will compare event.date with datetime.now() and use it in the template. Don't put unnecessary logic into template.

Or as Manoj suggested, you can have a custom filter in_the_future and call it:

{% if event.date|in_the_future %}

It's as simple as:

@register.filter
def in_the_future(value):
    return value > datetime.now()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜