开发者

Finding the Difference in DateTimeFields

开发者 https://www.devze.com 2022-12-17 06:56 出处:网络
I\'m trying to find if two DateTimeFields are greater than 2 days difference in a template.Is t开发者_Python百科his possible to do in a template?There\'s no built-in way to do this inside a template.Y

I'm trying to find if two DateTimeFields are greater than 2 days difference in a template. Is t开发者_Python百科his possible to do in a template?


There's no built-in way to do this inside a template. You could first calculate the day difference in the view, but I doesn't sound like that's what you want.

The easiest way to do this inside a template would be to write a custom template filter. (Custom template filters are quite a bit easier than creating custom tags, by the way.)

http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#writing-custom-template-filters


Calculation should not be done in the template. Calculate in the view and pass it in as a context variable.

0

精彩评论

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

关注公众号