google-app-engine


Jinja2 install issue


I am getting the following error message when attempting {% set foo = 42 %} in my html template. The template works fine when the set is not used.
TemplateSyntaxError: Invalid block tag: 'set', expected 'endblock' or 'endblock content'
Below I have added the full session log as suggested in comments.
*** Running dev_appserver with the following flags:
--skip_sdk_update_check=yes --port=15093 --admin_port=8018
Python command: /usr/bin/python2.7
INFO 2016-05-14 18:36:26,513 devappserver2.py:762] Skipping SDK update check.
INFO 2016-05-14 18:36:26,696 api_server.py:204] Starting API server at: http://localhost:56265
INFO 2016-05-14 18:36:26,701 dispatcher.py:197] Starting module "default" running at: http://localhost:15093
INFO 2016-05-14 18:36:26,704 admin_server.py:118] Starting admin server at: http://localhost:8018
ERROR 2016-05-14 18:37:48,778 webapp2.py:1528] Invalid block tag: 'set', expected 'endblock' or 'endblock content'
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1511, in __call__
rv = self.handle_exception(request, response, e)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1505, in __call__
rv = self.router.dispatch(request, response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
return route.handler_adapter(request, response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1077, in __call__
return handler.dispatch()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 547, in dispatch
return self.handle_exception(e, self.app.debug)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 545, in dispatch
return method(*args, **kwargs)
File "/Users/brian/googleapps/lastturn/views.py", line 187, in get
self.response.out.write(template.render(path, template_values))
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/template.py", line 91, in render
t = _load_internal_django(template_path, debug)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/template.py", line 165, in _load_internal_django
template = django.template.loader.get_template(file_name)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/_internal/django/template/loader.py", line 160, in get_template
template = get_template_from_string(template, origin, template_name)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/_internal/django/template/loader.py", line 168, in get_template_from_string
return Template(source, origin, name)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/_internal/django/template/__init__.py", line 158, in __init__
self.nodelist = compile_string(template_string, origin)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/_internal/django/template/__init__.py", line 186, in compile_string
return parser.parse()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/_internal/django/template/__init__.py", line 281, in parse
compiled_result = compile_func(self, token)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/_internal/django/template/loader_tags.py", line 195, in do_extends
nodelist = parser.parse()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/_internal/django/template/__init__.py", line 281, in parse
compiled_result = compile_func(self, token)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/_internal/django/template/loader_tags.py", line 173, in do_block
nodelist = parser.parse(('endblock', 'endblock %s' % block_name))
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/_internal/django/template/__init__.py", line 279, in parse
self.invalid_block_tag(token, command, parse_until)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/_internal/django/template/__init__.py", line 332, in invalid_block_tag
raise self.error(token, "Invalid block tag: '%s', expected %s" % (command, get_text_list(["'%s'" % p for p in parse_until])))
TemplateSyntaxError: Invalid block tag: 'set', expected 'endblock' or 'endblock content'
ERROR 2016-05-14 18:37:48,784 wsgi.py:279]
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 267, in Handle
result = handler(dict(self._environ), self._StartResponse)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1519, in __call__
response = self._internal_error(e)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1511, in __call__
rv = self.handle_exception(request, response, e)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1505, in __call__
rv = self.router.dispatch(request, response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
return route.handler_adapter(request, response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1077, in __call__
return handler.dispatch()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 547, in dispatch
return self.handle_exception(e, self.app.debug)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 545, in dispatch
return method(*args, **kwargs)
File "/Users/brian/googleapps/lastturn/views.py", line 187, in get
self.response.out.write(template.render(path, template_values))
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/template.py", line 91, in render
t = _load_internal_django(template_path, debug)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/template.py", line 165, in _load_internal_django
template = django.template.loader.get_template(file_name)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/_internal/django/template/loader.py", line 160, in get_template
template = get_template_from_string(template, origin, template_name)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/_internal/django/template/loader.py", line 168, in get_template_from_string
return Template(source, origin, name)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/_internal/django/template/__init__.py", line 158, in __init__
self.nodelist = compile_string(template_string, origin)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/_internal/django/template/__init__.py", line 186, in compile_string
return parser.parse()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/_internal/django/template/__init__.py", line 281, in parse
compiled_result = compile_func(self, token)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/_internal/django/template/loader_tags.py", line 195, in do_extends
nodelist = parser.parse()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/_internal/django/template/__init__.py", line 281, in parse
compiled_result = compile_func(self, token)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/_internal/django/template/loader_tags.py", line 173, in do_block
nodelist = parser.parse(('endblock', 'endblock %s' % block_name))
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/_internal/django/template/__init__.py", line 279, in parse
self.invalid_block_tag(token, command, parse_until)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/_internal/django/template/__init__.py", line 332, in invalid_block_tag
raise self.error(token, "Invalid block tag: '%s', expected %s" % (command, get_text_list(["'%s'" % p for p in parse_until])))
TemplateSyntaxError: Invalid block tag: 'set', expected 'endblock' or 'endblock content'
INFO 2016-05-14 18:37:48,792 module.py:812] default: "GET / HTTP/1.1" 500 -
Below I have added the revisions I made to my views.py. The commented out lines indicate the original jinja2 environment statements. These revisions are in response to suggestions made in comments. But I still get the same error message which seems to suggest jinja2 is not being used.
TEMPLATE_DIR = os.path.join(os.path.dirname(__file__), 'templates')
#jinja_environment = \
#jinja2.Environment(loader=jinja2.FileSystemLoader(TEMPLATE_DIR))
JINJA_ENVIRONMENT = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
extensions=['jinja2.ext.autoescape'],
autoescape=True)
class BaseHandler(webapp2.RequestHandler):
#webapp2.cached_property
def jinja2(self):
return jinja2.get_jinja2(app=self.app)
def render_template(
self,
filename,
template_values,
**template_args
):
#template = jinja_environment.get_template(filename)
template = JINJA_ENVIRONMENT.get_template(filename)
self.response.out.write(template.render(template_values))
Below is the base.html template.
<html>
<head>
<link rel="stylesheet" href="/static/css/reset.css">
<link rel="stylesheet" href="/static/css/style.css">
</head>
<body>
<div class="wrapper">
{% block content %}
{% endblock content %}
</div>
</body>
</html>
Below is the "heart" of the actual template. By "heart", I mean I have left out the guts because this is just a test.
{% extends "base.html" %}
{% block content %}
<center>
<h1>Create or edit your own Blog</h1>
</center>
{% set foo = 42 %}
{{ foo }}
{% endblock content %}
This answer suggests to me that jinja2 is not installed (properly?).
Is there some other part of installation that I have to change?
This answer shows more input about ipython installation, but I am using google-app-engine which may be different. The listing below confirms that Jinja2 2.8 is installed.
server:~ brian$ pip freeze
Warning: cannot find svn location for setuptools===0.6c12dev-r85381
all==0.0.6
altgraph==0.7.1
atari-py==0.0.17
bdist-mpkg==0.4.4
bonjour-py==0.3
caller-module==0.0.9
Django==1.3.1
include-server===3.1-toolwhip.1
Jinja2==2.8
macholib==1.3
MarkupSafe==0.23
mod-python==3.3.1
modulegraph==0.8.1
numpy==1.11.0
PIL==1.1.7
Pillow==3.2.0
public==0.0.0
py2app==0.5.3
pyglet==1.2.4
pyobjc-core==2.3.2a0
pyobjc-framework-AddressBook==2.3.2a0
pyOpenSSL==0.12
PyRSS2Gen==1.0.0
python-dateutil==1.5
PyYAML==3.11
render==1.0.0
requests==2.9.1
six==1.10.0
Twisted==11.0.0
xattr==0.6.1
zope.interface==3.5.1
You are using pip version 8.1.1, however version 8.1.2 is available.
server:~ brian$
After much help via comments to my original question, and to much stumbling, I have finally answered my question. I was confused by both webapp2 and Jinja having a template.render() but they are different.
template.render() from webapp seems to require 2 parameters -- the path and the template name -- and my current code uses this format. However, I want to use Jinja2 where template.render() requires only 1 parameter -- the template name.
According to the google docs for using Jinja in the guestbook app the following format was shown.
JINJA_ENVIRONMENT = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
extensions=['jinja2.ext.autoescape'],
autoescape=True)
But it turns out that does not work well with my chosen BaseHandler class which puts templates in their own subdirectory, "templates". Instead I used the following code where TEMPLATE_DIR replaces file in the "loader=" sentence .
TEMPLATE_DIR = os.path.join(os.path.dirname(__file__), 'templates')
JINJA_ENVIRONMENT = jinja2.Environment(
loader=jinja2.FileSystemLoader(TEMPLATE_DIR ),
extensions=['jinja2.ext.autoescape'],
autoescape=True)
Btw, I no longer import the webapp template. And I use the following style in my "get def"s.
template = JINJA_ENVIRONMENT.get_template('index.html')
self.response.out.write(template.render( template_values))
So, although the question asks "Jinja install issue", it was not exactly the install that was problematic, rather I had difficulty integrating Jinja with my existing directory structure.

Related Links

How to enable speech api higher quota
Google App Engine standard environment to Cloud-SQL Second Generation instance
GAE: Restore ah-builtin-python-bundle and ah-builtin-datastoreservice
Google Cloud Storage Force Download
Importing data into 2nd generation google cloud sql
App Engine: What is the Maximum URLFetch Timeout Deadline in a Taskqueue / Backend
Using URL-safe keys in Google Cloud Datastore
AttributeError on google cloud datastore entity object
Is there any way to handle Google Datastore Kind Property names with spaces in Golang?
Google App Engine: Disable favicon.ico
Google Cloud DataStore. How to serve data?
How to access a cloud storage bucket from app engine without getting the 403 FORBIDDEN error?
Google App Engine Custom Domain - Routing in Go
Best approach for caching lists of objects in memcache
com.google.gcloud.datastore vs com.google.appengine.api.datastore
Google App Engine - Issue with creating a bulkloading config

Categories

HOME
url-redirection
grok
css3
rdbms
pascal
error-handling
replace
opendj
parameters
maxscript
nstableheaderview
sendgrid-api-v3
spin
enthought
ycsb
automatic-ref-counting
coin3d
glyphicons
vuejs
symfony-console
cfml
cgbitmapcontext
libigl
windows-server-2003
google-cloud-print
interbase
outliers
android-things
paperjs
sqsh
boost-asio
hard-drive
indy10
reverse
getlasterror
sharepoint-workflow
zoomify
ods
loading
metawidget
xv6
levenshtein-distance
apriori
contract
knime
file-sharing
openresty
dotnet-httpclient
remedy
reindex
avx
arules
polyline
rocks
angular2-testing
jodd
hclust
swizzling
project-organization
beanstalk
grass
kendo-upload
mobiledoc-kit
pyobjc
iiop
tweenlite
create.js
jjaql
maven-scm
spring-3
embedded-fonts
away3d
isqlquery
jeromq
mvc-editor-templates
ui-select2
font-awesome-4.0.0
panda3d
monotouch.dialog
saleslogix
rmiregistry
cuda-gdb
subproject
extconf.rb
mapping-by-code
wiimote
msr
delimited-text
office-2007
dot-emacs
burndowncharts
wysiwym

Resources

Encrypt Message