2

Hi i have an appengine application with the following db.Model:

class Cinema(db.Model):
    name = db.StringProperty()
    address = db.StringProperty()
    distance = db.IntegerProperty()
    user = db.ReferenceProperty(RunningUser)

When I fill my template everythings works fine:

            {% for cinema in cinemas %}
                <tr>
                    <td><img src="/images/cinema.png"></td>
                    <td>
                        <a href="...">
                            <h2>{{cinema.name}}</h2>
                        </a>
                        {{cinema.address}}
                    </td>
                    <td>
                        {% if cinema.distance > 10000 %}
                            <p>red</p>
                        {% endif %}
                    </td>
                </tr>
            {% endfor %}

Except the if statement. Python raises a TemplateSyntaxError: 'if' statement improperly formatted exception. According to Django it should be fine. So what is wrong with these three lines?

{% if cinema.distance > 10000 %}
    <p>red</p>
{% endif %}
Franziskus Karsunke
  • 4,948
  • 3
  • 40
  • 54
  • 1
    Make sure that you are referring to the same version of django documentation which you use on appengine. – Ski Sep 06 '11 at 18:19
  • Thanks for the answer. Version 0.96 (whish is the standard version of appengine) does not support the greater operator. – Franziskus Karsunke Sep 06 '11 at 21:21
  • 1
    Appengine has django 1.2. You can change the version with `use_library` (http://stackoverflow.com/questions/4994913/app-engine-default-django-version-change). Though my personal opinion is that django is not suited for appengine. I would recommend `Kay Framework` or `Flask` over Django. I think Django is just a huge overhead and cause headaches when used on appengine. – Ski Sep 06 '11 at 21:26
  • Thanks for this info. I am using django with appengine and python. Especially for my purposes (i am only using the template system) it produces no overhead and is very good for my prototype webapps. – Franziskus Karsunke Sep 07 '11 at 09:47

1 Answers1

1

try this:

{% if cinema.distance > 10000 %}
    <p>red</p>
{% endif %}

from: https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#id3

Arthur Neves
  • 11,840
  • 8
  • 60
  • 73
  • I tried all variations with brackets... none of it worked... Or did I miss a detail? – Franziskus Karsunke Sep 06 '11 at 21:00
  • the solution above MUST work! if you are still getting the error, it might be somewhere else in your template! double check all if tags! and confirm if you are closing the block(endif)! – Arthur Neves Sep 06 '11 at 21:04
  • I think the problem is that I am using the standard django version of appengine (which is 0.96). It seems that this version doesn't support the > operator. – Franziskus Karsunke Sep 06 '11 at 21:09
  • 1
    Completely right! if you check the version1.0 docs: https://docs.djangoproject.com/en/1.0/ref/templates/builtins/?from=olddocs#if you can see that there is no > operator! too bad!! so you can return a Boolean variable from your view to your template! – Arthur Neves Sep 06 '11 at 21:16