django / django/new-features

Support variables in the `{% now %}` template tag

Open
#115 3 comments 17 reactions 0 assignees View on GitHub
Django Core Templates
Dominant language
No language data
Stars
188
Forks
7
PR merge metrics
No merged PRs in 30d

Description

### Code of Conduct

- [x] I agree to follow Django's Code of Conduct

### Feature Description

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

### Problem

[Django's `{% now %}` template tag](https://docs.djangoproject.com/en/6.0/ref/templates/builtins/#now) 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).

### Request or proposal

proposal

### Additional Details

[As I explain in my blog post](https://blog.lilyf.org/posts/django-template-quirks-3/#the--now--tag), 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`.

### Implementation Suggestions

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.