backend/django
Django: template tag 'now'
seul chan
2018. 4. 5. 11:02
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 %}