无法为DateTimeProperty创建空值

时间:2014-04-17 12:10:22

标签: python google-app-engine google-cloud-datastore jinja2

我在GAE数据存储区上使用DateTimeProperty。

date_posted = db.DateTimeProperty()

然后我需要与jinja2进行比较。

{% if i.date_posted is defined %}
  {{ i.date_posted.strftime('%d %b %Y') }}
{% else %}
  No
{% endif %}

在GAE SDK控制台上,我的条目是:

  

date_posted(无)

但我的比较并没有把它当作零。

1 个答案:

答案 0 :(得分:1)

你可以试试这个:

{{ i.date_posted.strftime('%d %b %Y')  if i.date_posted != None  }}