【问题标题】:Trying to format Google App Engine DateTimeProperty with a template modifier尝试使用模板修饰符格式化 Google App Engine DateTimeProperty
【发布时间】:2011-07-01 23:27:20
【问题描述】:

好吧,我有一个带有 DateTimeProperty() 类型的日期时间字段的数据库模型。我想在我的模板中格式化这个值,所以我使用:

{{row.datetime|date:'M j, H:i'}}

但 Google App Engine 会抛出此异常:

Traceback(最近一次调用最后一次):
  __call__ 中的文件“/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/__init__.py”,第 515 行
    handler.get(*groups)
  文件“/base/data/home/apps/.../1.348530548823349202/main.py”,第 22 行,在 get
    'nominations': row.nominations} 用于数据中的行]
  文件“/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/template.py”,第 155 行,在渲染中
    t = 加载(模板路径,调试)
  加载中的文件“/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/template.py”,第 183 行
    模板 = django.template.loader.get_template(file_name)
  文件“/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/loader.py”,第 80 行,在 get_template
    模板 = get_template_from_string(来源、来源、模板名称)
  文件“/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/loader.py”,第 88 行,在 get_template_from_string
    返回模板(来源、来源、名称)
  文件“/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/__init__.py”,第 158 行,在 __init__
    self.nodelist = compile_string(template_string, origin)
  文件“/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/__init__.py”,第 174 行,在 compile_string
    返回 parser.parse()
  解析中的文件“/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/__init__.py”,第 273 行
    编译结果 = 编译函数(自我,令牌)
  文件“/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/defaulttags.py”,第 544 行,在 do_for
    nodelist_loop = parser.parse(('endfor',))
  解析中的文件“/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/__init__.py”,第 254 行
    filter_expression = self.compile_filter(token.contents)
  文件“/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/__init__.py”,第 338 行,在 compile_filter
    返回FilterExpression(令牌,自我)
  文件“/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/__init__.py”,第 558 行,在 __init__
    引发 TemplateSyntaxError,“无法解析余数:%s”% token[upto:]
TemplateSyntaxError: 无法解析余数: :'M j, H:i'

我做错了什么?

提前谢谢你。

【问题讨论】:

    标签: templates datetime date-formatting djangoappengine


    【解决方案1】:

    试试

    {{row.datetime|date:"M j, H:i"}}
    

    【讨论】:

    • 双引号要求有记录吗?仅供参考。 :)
    猜你喜欢
    • 2011-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-20
    • 2014-01-27
    • 2017-10-04
    相关资源
    最近更新 更多