zjm1126 zjm1126 - 1 month ago 5
Python Question

does webapp has 'elseif' or 'elif' in template tags

my code is :

{% if user %}
<p>Logged in as {{ user.first_name }} {{ user.last_name }}.</p>
{% elif openid_user%}
<p>Hello, {{openid_user.nickname}}! Do you want to <a href="{{openid_logout_url}}">Log out?</p>
{% else %}
<p><a href="/login?redirect={{ current_url }}">google Log in</a>.</p>
<p><a href="/twitter">twitter Log in</a>.</p>
<p><a href="/facebook">facebook Log in</a>.</p>
<p><a href="{{openid_login_url}}">openid Log in</a>.</p>
<iframe src="/_openid/login?continue=/"></iframe>
{% endif %}

the error is :

TemplateSyntaxError: Invalid block tag: 'elif'

does not webapp has a 'else if ' ?



webapp per se has no templates, but you can use Django templates - by default, those from back in Django 0.96 (as you see from the ancient docs I pointed to, that requires the nested if to be physically nested inside the else block). You can use a more updated version of Django (see here for more details) by starting your Python code with

import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

from google.appengine.dist import use_library
use_library('django', '1.1')

but while this does give you a template language that's vastly improved in many ways, those improvements do not include an elseif or elif tag -- you still have to explicitly nest the secondary if inside the primary one's else branch.