I get an UnboundLocalError
because I use a template value inside an if statement which is not executed. What is the standard way to handle this situation?
class Test(webapp.RequestHandler):
def get(self):
user = users.get_current_user()
if user:
greeting = ('Hello, ' + user.nickname())
else:
self.redirect(users.create_login_url(self.request.uri))
...
template_values = {"greeting": greeting,
}
Error:
UnboundLocalError: local variable 'greeting' referenced before assignment