Python Can';不能为DateTimeProperty设置空值
我正在GAE数据存储上使用DateTimePropertyPython Can';不能为DateTimeProperty设置空值,python,google-app-engine,google-cloud-datastore,jinja2,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控制台上,我的条目显示: 发布日期(无) 但我的比较结果并没有显示为空。您可以尝试以下方法: {{ i
date_posted = db.DateTimeProperty()
然后,我需要与jinja2进行比较
{% if i.date_posted is defined %}
{{ i.date_posted.strftime('%d %b %Y') }}
{% else %}
No
{% endif %}
在GAE SDK控制台上,我的条目显示:
发布日期(无)
但我的比较结果并没有显示为空。您可以尝试以下方法:
{{ i.date_posted.strftime('%d %b %Y') if i.date_posted != None }}
我对Jinja2不太了解:被定义和没有定义之间有区别吗?也就是说,它可以被定义为“无”吗?太好了!我只需要加上一个“else‘No’”,它就被排序了。非常感谢。