尝试使用模板修饰符格式化 Google App Engine DateTimeProperty
好吧,我有一个带有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
try