google app engine - Error with rendering webapp2 -
good personal day. have problem can not solve.
it happens in app creating have 3 files: main, config , home.html
the config file used grab user data , adds them dictionary. if user not exist in datastore, adds.
#!/usr/bin/env python # -*- coding: utf-8 -*- google.appengine.api.app_identity import get_default_version_hostname google.appengine.ext import ndb url = get_default_version_hostname() # banco de dados para salvar os usuarios class usuarios(ndb.model): usuario = ndb.stringproperty() email = ndb.stringproperty() openid = ndb.stringproperty() date = ndb.datetimeproperty(auto_now_add=true) tipo = ndb.stringproperty() @classmethod def get_email(cls, email): return cls.query(cls.email == email) ########### funÇÃo que chama o login ######## def redir(): google.appengine.api import users user = users.get_current_user() if users.is_current_user_admin(): redir = 'http://' + url + '/admin' else: redir = none return redir def geral(): google.appengine.api import users user = users.get_current_user() providers = { 'google' : 'https://www.google.com/accounts/o8/id', 'yahoo' : 'yahoo.com', } rt = { 'titulo' : 'beta hcbravin', 'version' : '14.11.10', 'url' : 'http://' + url, } # o usuario esta logado? if user: # o usuario e um administrador? if users.is_current_user_admin(): dtipo = 'admin' else: dtipo = 'aluno' # o usuario existe no banco de dados? quser = usuarios.get_email(user.email()) buser = quser.get() if not buser: dbuser = usuarios(usuario = user.nickname(), email = user.email(), openid = user.user_id(), tipo = dtipo) dbuser.put() if buser: if buser.tipo == 'professor': dtipo = 'professor' else: dtipo = 'aluno' rt.update({ 'usuario': user.nickname(), 'email': user.email(), 'openid': user.user_id(), 'logout_url': users.create_logout_url('/'), 'user_tipo': dtipo, }) else: # let user choose authenticator #login_url = {'usuario': none, 'logout_url': none} login_url = {} name, uri in providers.items(): login_url[name] = users.create_login_url(dest_url = ('/usuario') ,federated_identity=uri) rt.update(login_url) return rt ########## ############
the main file main file of app renders home.html
import os import webapp2 import sys config import * google.appengine.ext.webapp import template google.appengine.ext.webapp.util import run_wsgi_app geral = geral() class mainhandler(webapp2.requesthandler): def get(self): self.response.out.write(template.render('home.html', geral)) app = webapp2.wsgiapplication([ ('/', mainhandler), ], debug=true)
the home.html has value variable {{ email }}
, print (that's not all, logical. bad using simplest approach)
the problem: when login user shows email. if make out , user mute rather appearing email "new" keeps popping old email.
this remains if refresh page.
code outside of handler's methods runs when instance starts up, not once-per-request. call geral = geral()
isn't being repeated visitors after first one.
you should move line inside method (and change name on left-hand-side not same function-name!)
Comments
Post a Comment