I
I
Ilya2014-08-19 03:37:14
Django
Ilya, 2014-08-19 03:37:14

Django doesn't show date using |date conversion, where to look for error?

There is a model in models.py

class PublicField(models.Model):
    pub_date = models.DateTimeField(auto_now_add=True)

there is a function in views.py
def public_field(request, publicfield_id):
    publicfield = PublicField.objects.get(id=publicfield_id)
    return render_to_response('my_template.html', {'publicfield': publicfield})

And there is a template
{{ publicfield.pub_date|date }}
AND the date is not displayed. but if you remove "|date", then it is shown
2014-08-13 20:28:26.896337
But this is not very suitable for me.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mefisto, 2014-08-19
@FireGM

Apparently, you either have a string and not a datetime object fed to the |date filter, or this is a bug regarding the date filter and dates with timezones

A
Alexander, 2014-08-19
@syschel

{{ publicfield.pub_date|date:"d.m.Y" }}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question