templates filters =>naturaltime
1.安裝Django Humanize 在 INSTALLED_APPS加入
'django.contrib.humanize'
INSTALLED_APPS=[
'django.contrib.auth',
'django.contrib.humanize',
...
]
2使用
在templates檔案中要先load tag
{% load humanize %}
{{ notification.date|natualtime }}
常用的 template filter
filter examplae
apnumber 1 => one
intcomma 4500000 => 4,500,000
intword 1200000 => 1.2 million
naturalday 08 May 2016 => yesterday
naturaltime 09May 2016 20:54:31 => 29 seconds ago
ordinal 3 => 3rd
其餘請參考django document
'django.contrib.humanize'
INSTALLED_APPS=[
'django.contrib.auth',
'django.contrib.humanize',
...
]
2使用
在templates檔案中要先load tag
{% load humanize %}
{{ notification.date|natualtime }}
常用的 template filter
filter examplae
apnumber 1 => one
intcomma 4500000 => 4,500,000
intword 1200000 => 1.2 million
naturalday 08 May 2016 => yesterday
naturaltime 09May 2016 20:54:31 => 29 seconds ago
ordinal 3 => 3rd
其餘請參考django document
留言
張貼留言