【发布时间】:2011-12-19 04:15:50
【问题描述】:
我来自 Rails 编程经验。
我正在使用 Django 模板在 Google App Engine 上使用 Python 编写应用程序。
我不能在日期时间调用 strftime("%I:%M %p")。
在我的 main.py 文件中,我有:
import datetime
....
class Report(db.Model):
date = db.DateTimeProperty(auto_now_add = True)
我将所有报告传递给模板,并且在我拥有的模板中:
{% for report in reports %}
<tr>
<td>{{ report.date.strftime("%I:%M %p") }}</td>
</tr>
{% endfor %}
我知道我有一个日期时间对象,因为我可以做到:
{{ report.date.day }}
或:
{{ report.date.minute }}
很好,他们会返回他们应该返回的东西。
当我有的时候:
{{ report.date.strftime("%I:%M %p") }}
我得到错误:
raise TemplateSyntaxError, "Could not parse the remainder: %s" % token[upto:]
TemplateSyntaxError: Could not parse the remainder: ("%I:%M %p")
如何让 strftime 工作?
【问题讨论】:
标签: python google-app-engine methods django-templates