When want to use now
date or datetime in django temlpate, you can pass datetime.now()
for context data.
But you can simply use now
template tag. It displays the current date and/or time, using a format.
<p>
the time is {% now "jS F Y H:i" %}
</p>
You can pass predefined ones : DATE_FORMAT
, DATETIME_FORMAT
, SHORT_DATE_FORMAT
, SHORT_DATETIME_FORMAT
like this.
<p>
it is {% now "SHORT_DATE_FORMAT" %}
</p>
Also you can use syntax like {% now 'Y' as current_year %}
.
{% now "Y" as current_year %}
{% blocktrans %}Copyright {{ current_year }}{% endblocktrans %}
'backend > django' 카테고리의 다른 글
Django: get all logged-in users by using session (0) | 2018.04.15 |
---|---|
Django: django channels basic usage (0) | 2018.04.06 |
Django: use crontab easy in django - django-crontab (0) | 2018.04.04 |
Django: multiple pagination in CBV (0) | 2018.03.30 |
django: 기본 비밀번호 validation 수정하기 (0) | 2018.03.22 |