Google App Engine (python): TemplateSyntaxError: five-word "for" instructions must end with "reverse"

This uses the web application framework, not Django.

The following template code gives me the expression TemplateSyntaxError: 'for', containing five words, should end up with a reverseed error when trying to create a dictionary. I don't understand what causes this error. Can someone shed some light on this for me?

{% for code, name in charts.items %} <option value="{{code}}">{{name}}</option> {% endfor %} 

I process it using the following:

 class GenerateChart(basewebview): def get(self): values = {"datepicker":True} values["charts"] = {"p3": "3D Pie Chart", "p": "Segmented Pied Chart"} self.render_page("generatechart.html", values) class basewebview(webapp.RequestHandler): ''' Base class for all webapp.RequestHandler type classes ''' def render_page(self, filename, template_values=dict()): filename = "%s/%s" % (_template_dir, filename) path = os.path.join(os.path.dirname(__file__), filename) self.response.out.write(template.render(path, template_values)) 
+6
python google-app-engine django django-templates
source share
1 answer

This uses the web application framework, not Django.

But on the other hand, you should use Django templates - and, apparently, in the old version that does not support the "automatic unpack" for style - perhaps 0.96 , which is the default for App Engine. To use any part of more modern Django (including "templates only"), you must have the settings.py file and do:

 import os os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' from google.appengine.dist import use_library use_library('django', '1.1') 

according to the documents . After that, you can from django import template , and you will use the version of the Django template engine version 1.1.

+13
source share

All Articles