尝试使用模板修饰符格式化 Google App Engine DateTimeProperty

发布于 2024-10-18 13:43:44 字数 2510 浏览 1 评论 0原文

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

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

但是Google App Engine抛出这个异常:

Traceback (most recent call last):
  File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 515, in __call__
    handler.get(*groups)
  File "/base/data/home/apps/.../1.348530548823349202/main.py", line 22, in get
    'nominations': row.nominations} for row in data]
  File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/template.py", line 155, in render
    t = load(template_path, debug)
  File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/template.py", line 183, in load
    template = django.template.loader.get_template(file_name)
  File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/loader.py", line 80, in get_template
    template = get_template_from_string(source, origin, template_name)
  File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/loader.py", line 88, in get_template_from_string
    return Template(source, origin, name)
  File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/__init__.py", line 158, in __init__
    self.nodelist = compile_string(template_string, origin)
  File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/__init__.py", line 174, in compile_string
    return parser.parse()
  File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/__init__.py", line 273, in parse
    compiled_result = compile_func(self, token)
  File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/defaulttags.py", line 544, in do_for
    nodelist_loop = parser.parse(('endfor',))
  File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/__init__.py", line 254, in parse
    filter_expression = self.compile_filter(token.contents)
  File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/__init__.py", line 338, in compile_filter
    return FilterExpression(token, self)
  File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/__init__.py", line 558, in __init__
    raise TemplateSyntaxError, "Could not parse the remainder: %s" % token[upto:]
TemplateSyntaxError: Could not parse the remainder: :'M j, H:i'

我做错了什么?

先感谢您。

Well, I've a database model with a datetime field of type DateTimeProperty(). I want to format this value in my template, so I'm using:

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

But Google App Engine throws this exception:

Traceback (most recent call last):
  File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 515, in __call__
    handler.get(*groups)
  File "/base/data/home/apps/.../1.348530548823349202/main.py", line 22, in get
    'nominations': row.nominations} for row in data]
  File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/template.py", line 155, in render
    t = load(template_path, debug)
  File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/template.py", line 183, in load
    template = django.template.loader.get_template(file_name)
  File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/loader.py", line 80, in get_template
    template = get_template_from_string(source, origin, template_name)
  File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/loader.py", line 88, in get_template_from_string
    return Template(source, origin, name)
  File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/__init__.py", line 158, in __init__
    self.nodelist = compile_string(template_string, origin)
  File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/__init__.py", line 174, in compile_string
    return parser.parse()
  File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/__init__.py", line 273, in parse
    compiled_result = compile_func(self, token)
  File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/defaulttags.py", line 544, in do_for
    nodelist_loop = parser.parse(('endfor',))
  File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/__init__.py", line 254, in parse
    filter_expression = self.compile_filter(token.contents)
  File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/__init__.py", line 338, in compile_filter
    return FilterExpression(token, self)
  File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/template/__init__.py", line 558, in __init__
    raise TemplateSyntaxError, "Could not parse the remainder: %s" % token[upto:]
TemplateSyntaxError: Could not parse the remainder: :'M j, H:i'

What am I doing wrong?

Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

塔塔猫 2024-10-25 13:43:44

尝试

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

try

{{row.datetime|date:"M j, H:i"}}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文