views:

178

answers:

1

This is using the web app framework, not Django.

The following template code is giving me an TemplateSyntaxError: 'for' statements with five words should end in 'reversed' error when I try to render a dictionary. I don't understand what's causing this error. Could somebody shed some light on it for me?

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

I'm rendering 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))
+11  A: 

This is using the web app framework, not Django.

But framework apart, you must be using Django's templating -- and apparently in an old version, which does not support the "automatic unpacking" style of for -- probably the 0.96 version that's the default for App Engine. To use any part of more modern Django (including "just the templates") you must have a 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')

as per the docs. After that you can from django import template and you'll be using the 1.1 version of Django's templating engine.

Alex Martelli
Martellipedia does it again! Thanks.
Phil
@Phil, you're welcome!-)
Alex Martelli