【发布时间】:2015-10-18 04:44:29
【问题描述】:
我想找出某个日期与 15 天后的日期之间的天数。 我创建了一个个人过滤器:
register = template.Library()
import datetime
@register.filter
def nbDays(thedate):
res = 0
passed = datetime.datetime.now() - thedate
res = 15 - passed
return res
我有这个错误:
can't subtract offset-naive and offset-aware datetimes
当我调用方法时:
{% load nameOfFile %}
{{ objectGood.created_at|nbDays }}
【问题讨论】:
-
你的设置中有
USE_TZ = True吗? -
不,我搜索如何使用它
-
是真的:我有这个 USE_I18N = True USE_L10N = True USE_TZ = True
标签: python django django-templates django-filter django-template-filters