Milano Slesarik Milano Slesarik - 3 months ago 15
Python Question

Changing time format in template is raising exception

I can't figure out why

Django
returns
Exception
when I try to set time format in template.

This is a column in
Django-tables2
table.

time_arrival = tables.TemplateColumn('{{record.time_arrival|time: "H:i"}}',verbose_name=u'Čas príchodu')


The
time_arrival
is an attribute of
Reservation
model which is a
record
in this table. When there is just
{{ record.time_arrival }}
it shows time in this format:
1 p.m.
but I want to show
13:00
for example so I have to change the format.

This exception is being raised:

Exception Value: Could not parse the remainder: ': "H:i"' from 'record.time_arrival|time: "H:i"'


This is a
time_arrival
attribute in
Reservation
model:

time_arrival = models.TimeField(null=True, blank=True, verbose_name=u'Čas príletu')


Do you know where is the problem?

Answer

Remove the space between time: and "H:i"

'{{record.time_arrival|time:"H:i"}}'
Comments