Invalid Block Tag i=0, in Django
I was going through Appengine's Getting Started guide for python, while reading up [templates][1],I modified the code(which is a simple guestbook) to include simple numbering next to the guestbook entries.

In index.html i added the (what I thought would be) relevant code. 

**index.html (I have added {%i=0%} on line 3,{%i+=1%} on line 5, and {{i}} on line 7, the rest is from the guide):** 

    <html>
      <body>
        {%i=0%}
     {% for greeting in greetings %}
        {%i+=1%}
       {% if greeting.author %}
            <b>{{i}}:{{ greeting.author.nickname }}</b> wrote:
          {% else %}
           An anonymous person wrote:
          {% endif %}
          <blockquote>{{ greeting.content|escape }}</blockquote>
        {% endfor %}
    
        <form action="/sign" method="post">
          <div><textarea name="content" rows="3" cols="60"></textarea></div>
          <div><input type="submit" value="Sign Guestbook"></div>
        </form>
    
        <a href="{{ url }}">{{ url_linktext }}</a>
    
      </body>
    </html>

I got the following error

> TemplateSyntaxError: Invalid block
> tag: 'i=0'

I read up Django's help on [templates][2], which says that 

> The Django template system provides
> tags which function similarly to some
> programming constructs – an if tag for
> boolean tests, a for tag for looping,
> etc. – but these are not simply
> executed as the corresponding Python
> code, and the template system will not
> execute arbitrary Python expressions.

So I guess, that performing calculations is not what the templating system is for. 

***tl;dr***  

**Can anyone tell me how to number my entries or use the "counter - increment" construct using Django templates?** 


I don't thing this code is necessary, but to complete the picture,

**Unchanged helloworld.py code:**

    import os
    from google.appengine.ext.webapp import template
    import cgi
    
    from google.appengine.api import users
    from google.appengine.ext import webapp
    from google.appengine.ext.webapp.util import run_wsgi_app
    from google.appengine.ext import db
    
    class Greeting(db.Model):
        author = db.UserProperty()
        content = db.StringProperty(multiline=True)
        date = db.DateTimeProperty(auto_now_add=True)
    
    class MainPage(webapp.RequestHandler):
    def get(self):
        greetings_query = Greeting.all().order('-date')
        greetings = greetings_query.fetch(10)
    
        if users.get_current_user():
            url = users.create_logout_url(self.request.uri)
            url_linktext = 'Logout'
        else:
            url = users.create_login_url(self.request.uri)
            url_linktext = 'Login'
    
        template_values = {
            'greetings': greetings,
            'url': url,
            'url_linktext': url_linktext,
            }
    
        path = os.path.join(os.path.dirname(__file__), 'index.html')
        self.response.out.write(template.render(path, template_values))
    class Guestbook(webapp.RequestHandler):
        def post(self):
            greeting = Greeting()
    
            if users.get_current_user():
                greeting.author = users.get_current_user()
    
            greeting.content = self.request.get('content')
            greeting.put()
            self.redirect('/')
    
    application = webapp.WSGIApplication(
                                         [('/', MainPage),
                                          ('/sign', Guestbook)],
                                         debug=True)
    
    def main():
        run_wsgi_app(application)
    
    if __name__ == "__main__":
        main()


  [1]: http://code.google.com/appengine/docs/python/gettingstarted/templates.html
  [2]: http://docs.djangoproject.com/en/dev/topics/templates/
Invalid Block Tag i=0, in Django
===

I was going through Appengine's Getting Started guide for python, while reading up [templates][1],I modified the code(which is a simple guestbook) to include simple numbering next to the guestbook entries.

In index.html i added the (what I thought would be) relevant code. 

**index.html (I have added {%i=0%} on line 3,{%i+=1%} on line 5, and {{i}} on line 7, the rest is from the guide):** 

    <html>
      <body>
        {%i=0%}
     {% for greeting in greetings %}
        {%i+=1%}
       {% if greeting.author %}
            <b>{{i}}:{{ greeting.author.nickname }}</b> wrote:
          {% else %}
           An anonymous person wrote:
          {% endif %}
          <blockquote>{{ greeting.content|escape }}</blockquote>
        {% endfor %}
    
        <form action="/sign" method="post">
          <div><textarea name="content" rows="3" cols="60"></textarea></div>
          <div><input type="submit" value="Sign Guestbook"></div>
        </form>
    
        <a href="{{ url }}">{{ url_linktext }}</a>
    
      </body>
    </html>

I got the following error

> TemplateSyntaxError: Invalid block
> tag: 'i=0'

I read up Django's help on [templates][2], which says that 

> The Django template system provides
> tags which function similarly to some
> programming constructs – an if tag for
> boolean tests, a for tag for looping,
> etc. – but these are not simply
> executed as the corresponding Python
> code, and the template system will not
> execute arbitrary Python expressions.

So I guess, that performing calculations is not what the templating system is for. 

***tl;dr***  

**Can anyone tell me how to number my entries or use the "counter - increment" construct using Django templates?** 


I don't thing this code is necessary, but to complete the picture,

**Unchanged helloworld.py code:**

    import os
    from google.appengine.ext.webapp import template
    import cgi
    
    from google.appengine.api import users
    from google.appengine.ext import webapp
    from google.appengine.ext.webapp.util import run_wsgi_app
    from google.appengine.ext import db
    
    class Greeting(db.Model):
        author = db.UserProperty()
        content = db.StringProperty(multiline=True)
        date = db.DateTimeProperty(auto_now_add=True)
    
    class MainPage(webapp.RequestHandler):
    def get(self):
        greetings_query = Greeting.all().order('-date')
        greetings = greetings_query.fetch(10)
    
        if users.get_current_user():
            url = users.create_logout_url(self.request.uri)
            url_linktext = 'Logout'
        else:
            url = users.create_login_url(self.request.uri)
            url_linktext = 'Login'
    
        template_values = {
            'greetings': greetings,
            'url': url,
            'url_linktext': url_linktext,
            }
    
        path = os.path.join(os.path.dirname(__file__), 'index.html')
        self.response.out.write(template.render(path, template_values))
    class Guestbook(webapp.RequestHandler):
        def post(self):
            greeting = Greeting()
    
            if users.get_current_user():
                greeting.author = users.get_current_user()
    
            greeting.content = self.request.get('content')
            greeting.put()
            self.redirect('/')
    
    application = webapp.WSGIApplication(
                                         [('/', MainPage),
                                          ('/sign', Guestbook)],
                                         debug=True)
    
    def main():
        run_wsgi_app(application)
    
    if __name__ == "__main__":
        main()


  [1]: http://code.google.com/appengine/docs/python/gettingstarted/templates.html
  [2]: http://docs.djangoproject.com/en/dev/topics/templates/