Django "naturalday" template filter: fall back to formatted date?

django, django-template-filters, django-templates

Solution

Pass the format after the `:`, like in date filter:

Date: {{ result_date|naturalday:"F d" }}

- `F` is a textual representation of month, e.g. `July`.

- `d` is a day of the month, 2 digits with leading zeros, e.g. `25`.

Hope that helps.

Problem

I'm using Django's naturalday template tag, but how do I format the date string if the supplied date is not today, tomorrow or yesterday? This is my template string: ``` Date: {{ result_date|naturalday }} ``` If `result_date` is today, yesterday or tomorrow, then the template displays the natural string. But if it's 10 days ago, how can I control the formatting of the date to display as "July 25"? The docs say: For dates that are the current day or within one day, return “today”, “tomorrow” or “yesterday”, as appropriate. Otherwise, format the date using the passed in format string. What does "the passed in format string" mean?

Original source