Opened 5 months ago

Closed 4 days ago

#37118 closed New feature (fixed)

Support variables in the {% now %} template tag

Reported by: Lily Owned by: zky
Component: Template system Version: 6.0
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This was discussed and accepted in ​https://github.com/django/new-features/issues/115.

Allow passing a variable from the template context into the {% now %} template tag to allow dynamically choosing the formatting.

​Django's `{% now %}` template tag currently only supports a hardcoded string format defined directly in the template, or one of a small number of specific settings. By supporting template variables, it would be possible to change the format dynamically (for example, based on a user's locale).

​As I explain in my blog post, the now tag has some very weird behaviour caused by assuming the format will always be a string. By expanding to support variables, we can also clean up these weird edge-cases by raising a TemplateSyntaxError.

Several other template tags support variables, so it should be fairly easy to reuse their implementation of this.

Change History (11)

comment:1 by zky, 5 months ago

Owner: set to zky
Status: new → assigned

comment:2 by zky, 5 months ago

Has patch: set

comment:3 by zky, 5 months ago

I have submitted PR #21349 for this feature. Would a triager please update the Triage Stage to Accepted so that the GitHub CI checks can run? Thank you very much!

comment:4 by JaeHyuckSa, 5 months ago

Triage Stage: Unreviewed → Accepted

comment:5 by zky, 5 months ago

Hello, my previous PR was closed because the ticket hadn't reached the 'Accepted' status. Here is my new PR: ​https://github.com/django/django/pull/21357. Thank you

comment:6 by Tim McCurrach, 5 months ago

Patch needs improvement: set

comment:7 by zky, 5 months ago

Patch needs improvement: unset

comment:8 by zky, 5 months ago

Updated the PR to address the review comments. All checks are passing now. Please take another look, thanks!

comment:10 by Lily, 3 weeks ago

Triage Stage: Accepted → Ready for checkin

comment:11 by Sarah Boyce <42296566+sarahboyce@…>, 4 days ago

Resolution: → fixed
Status: assigned → closed

In bef1986:

Fixed #37118 -- Added variable support to the {% now %} template tag.

Thank you to Lily, Tim McCurrach and 사재혁 for reviews.

Note: See TracTickets for help on using tickets.
Back to Top