Tech Forum Network

Programming, technical solutions and hot scripts
Home » TechQns » Django TemplateSyntaxError: Invalid filter: truncatechars

Django TemplateSyntaxError: Invalid filter: truncatechars

July 24, 2013 Posted by forumadmin under TechQns
Comments off

Getting TemplateSyntaxError: Invalid filter: 'truncatechars' in app engine. I’m using latest django library. As per “Third-party Libraries in Python 2.7 on appengine” django latest version is 1.4 and truncatechars is included in the same version (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>

In app.yaml

 libraries:
    - name: django
      version: latest

I have tried with library version: "1.4" and have the same issue.

Error:

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'

 

Asked By – Nijin Narayanan        Read Answers    

More Related Questions

  • Django Template Variables and Javascript When I render a page using the Django template renderer, I can pass in a dictionary variable containing various values to manipulate them in the page using {{ myVar }}. Is there a way to […]
  • How to define a methode which splits the given url (In python webapp2 for Google app engine) I want to set up a Google App Enging (GAE) app which provides a login functionality with OAuth2 and OAuth1 for Twitter, Facebook, ...., Therefore I chose the authomatic module […]
  • Country name from ISO short code in dictionary, how to deal with non-ascii chars I'm making a webapp that takes country short code (google app engine get from request header) and I want to get the country name (full name) not just the 2 letter initials. I tried making […]
  • Google App Engine: Create a Save as draft feature for an entity I would like to create a 'save as draft' feature for a long entity form. Consider the data structure example below: class BigEntity(ndb.Model): title = ndb.StringProperty() date […]
  • Python/Django Template Iterating through Strings and Lists I have an issue with Python/Django where I have either a String or a List of Strings being passed to a Template. If it is a list I need to iterate through it and output each String on a […]
  • Flask vs webapp2 for Google App Engine I'm starting new Google App Engine application and currently considering two frameworks: Flask and webapp2. I'm rather satisfied with built-in webapp framework that I've used for my […]
  • Change Django Templates Based on User-Agent I've made a Django site, but I've drank the Koolaid and I want to make an IPhone version. After putting much thought into I've come up with two options: Make a whole other site, like […]
  • Django, template context processors I have a weird problem, I want to add a global query using context processors. This is how I did it by following: made a processor.py in my app as such: from myproject.myapp.models […]
  • Image does not appear Django template I am trying to load some images into a template but it continues to appear as broken link My files and directories are as follows 1.views.py def home(request): #template = […]
  • Is there a HAML implementation for use with Python and Django I happened to stumble across HAML, an interesting and beautiful way to mark up contents and write templates for HTML. Since I use Python and Django for my web developing need, I would […]
0
  
Email
Tags: django, django-templates, google-app-engine, python, webapp2

Comments are closed.

« Mixed mode in Steam (wine/native)
chroot sftp not able to login »
Tech Forum Network powered by WordPress and The Clear Line Theme