Django's date/time formats have a code for displaying the am/pm part of times as either:
a.m.
or
AM
but not as:
am
i.e. lowercase without periods.
How do you render times with lowercase am/pm?
NOTE: I thought of the answer while typing in this question, so I figured instead of scrapping it I'd share my answer in case it's helpful to someone else.
Use the lower template tag with the time formatting tag, e.g. Note simply using the lower filter on a time object without the explicit time format filter doesn't work. But you can use the default time format, e.g.
Use {{ obj | capfirst }} to make uppercase the first character only. Using {{ obj | title }} makes it Camel Case.
From the documentation: {% extends variable %} uses the value of variable. If the variable evaluates to a string, Django will use that string as the name of the parent template. If the variable evaluates to a Template object, Django will use that object as the parent template.
Django Code The template tags are a way of telling Django that here comes something else than plain HTML. The template tags allows us to to do some programming on the server before sending HTML to the client.
Use the lower
template tag with the time
formatting tag, e.g.
{{object.time|time:"g:iA"|lower}}
renders as
12:30pm
compared to
{{object.time|time:"g:iA"}}
which renders as
12:30PM
Note simply using the lower
filter on a time object without the explicit time
format filter doesn't work. But you can use the default time format, e.g.
{{object.time|time|lower}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With