I’m coming from a Rails programming experience.
I’m coding an app in Python on Google App Engine with Django templates.
I can’t call strftime(“%I:%M %p”) on a datetime.
In my main.py file I have:
import datetime
....
class Report(db.Model):
date = db.DateTimeProperty(auto_now_add = True)
I pass all the reports to the template and in the template I have:
{% for report in reports %}
<tr>
<td>{{ report.date.strftime("%I:%M %p") }}</td>
</tr>
{% endfor %}
I know I have a datetime object because I can do:
{{ report.date.day }}
or:
{{ report.date.minute }}
Just fine and they return what they are supposed to return.
When I do have:
{{ report.date.strftime("%I:%M %p") }}
I get the error:
raise TemplateSyntaxError, "Could not parse the remainder: %s" % token[upto:]
TemplateSyntaxError: Could not parse the remainder: ("%I:%M %p")
How do I get strftime to work?
The Django template engine doesn’t support passing arguments to methods like that. To accomplish the same thing, try using the
datefilter:(Edited: fixed the syntax for the date string, because I’m stupid.)