Finding the Difference in DateTimeFields
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.
精彩评论