HTML template Date renders not reflecting specified format

Hi, hoping you can help with a query - I am trying to use the following date format specification to render my dates in a shorter format on my index.html template for UX purposes:

{{ article.created_on|date:"D M Y"}}

I try many different variations of the formatting, but the HTML template render of the date will not change from its current format (e.g. MARCH 24, 2022, 12:39PM)

My Model code (date field extract) is per below:

class Article(models.Model):
    created_on = models.DateTimeField(auto_now_add=True)

My View code is per below:

class ArticleList(generic.ListView):
    model = Article
    queryset = Article.objects.filter(status=1).order_by('-created_on')
    template_name = 'index.html'
    paginate_by = 6

And my HTML template extract is per below:

<p class="author">
       {{ article.created_on|date:"D M Y"}} 
</p>

I have tried disabling the L10N variable in settings.py, and setting it to False, but the rendered date still will not change format.

Any help you can provide would be much appreciated - thanks in advance:

Not that it directly helps you, but I can’t recreate the problem you’re describing here.

In [16]: from django.utils.timezone import now

In [17]: from django.template import Context, Template

In [18]: Template('{{ d|date:"D M Y" }}').render(Context({'d':now}))
Out[18]: 'Fri Mar 2022'

You might try something similar to this in your Django shell (I use shell_plus) to see what you get.

Otherwise, we may need to see the rest of your template.
(Note, your image is illegible. Screenshots in general do not help.)

Hi Ken, thanks very much for replying - unfortunately I think this may have been some sort of systems error on my end - I had spent close to an hour before posting this question trying different things to get it to wrok, and now I have came back and the date formats are all responding to my specified changes in the filter, so my code must have been correct but it was maybe a dev server issue possibly

So apologies i technically should not have needed to raise this question as my code works - but thanks once again for your help, much appreciated

1 Like