Getting TemplateSyntaxError: Invalid filter: 'truncatechars'
アプリエンジンで。最新のdjangoライブラリを使用しています。「appengine 上の Python 2.7 のサードパーティ ライブラリ」に従って、 django の最新バージョンは 1.4 でありtruncatechars
、同じバージョン ( django doc ) に含まれています。
index.py
import webapp2
import os
from google.appengine.ext.webapp import template
class MainHandler(webapp2.RequestHandler):
def get(self):
title = " Python, an interactive, object-oriented, extensible programming language."
template_values = {
'title': title,
}
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
index.html
<html>
<body>
{{title|truncatechars:9}} // Error returns
{{title|slice:"9"}}{% if title|length > 9 %}...{% endif %}
</body>
</html>
app.yaml 内
libraries:
- name: django
version: latest
私はライブラリで試しましたversion: "1.4"
が、同じ問題があります。
エラー:
File "/home/user/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "/home/user/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1595, in handle_exception
return handler(request, response, e)
File "/home/user/dimensionfinder/urls.py", line 43, in handle_500
response.write(template.render(path, template_values))
File "/home/user/google_appengine/google/appengine/ext/webapp/template.py", line 89, in render
t = _load_internal_django(template_path, debug)
File "/home/user/google_appengine/google/appengine/ext/webapp/template.py", line 163, in _load_internal_django
template = django.template.loader.get_template(file_name)
File "/home/user/google_appengine/google/appengine/_internal/django/template/loader.py", line 160, in get_template
template = get_template_from_string(template, origin, template_name)
File "/home/user/google_appengine/google/appengine/_internal/django/template/loader.py", line 168, in get_template_from_string
return Template(source, origin, name)
File "/home/user/google_appengine/google/appengine/_internal/django/template/__init__.py", line 158, in __init__
self.nodelist = compile_string(template_string, origin)
File "/home/user/google_appengine/google/appengine/_internal/django/template/__init__.py", line 186, in compile_string
return parser.parse()
File "/home/user/google_appengine/google/appengine/_internal/django/template/__init__.py", line 281, in parse
compiled_result = compile_func(self, token)
File "/home/user/google_appengine/google/appengine/_internal/django/template/defaulttags.py", line 693, in do_for
nodelist_loop = parser.parse(('empty', 'endfor',))
File "/home/user/google_appengine/google/appengine/_internal/django/template/__init__.py", line 262, in parse
filter_expression = self.compile_filter(token.contents)
File "/home/user/google_appengine/google/appengine/_internal/django/template/__init__.py", line 356, in compile_filter
return FilterExpression(token, self)
File "/home/user/google_appengine/google/appengine/_internal/django/template/__init__.py", line 538, in __init__
filter_func = parser.find_filter(filter_name)
File "/home/user/google_appengine/google/appengine/_internal/django/template/__init__.py", line 362, in find_filter
raise TemplateSyntaxError("Invalid filter: '%s'" % filter_name)
TemplateSyntaxError: Invalid filter: 'truncatechars'