Last active
August 29, 2015 13:57
-
-
Save nbortolotti/9517564 to your computer and use it in GitHub Desktop.
Web Forms en App Engine mediante webapp2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from google.appengine.api import users | |
import webapp2 | |
import cgi | |
pagina = """\ | |
<html> | |
<body> | |
<form action="/registro" method="post"> | |
<div><textarea name="content" rows="3" cols="60"></textarea></div> | |
<div><input type="submit" value="Registrar Solicitud"></div> | |
</form> | |
</body> | |
</html> """ | |
class Home(webapp2.RequestHandler): | |
def get(self): | |
self.response.write(pagina) #se carga el HTML correspondiente a la página | |
class Registro(webapp2.RequestHandler): | |
def post(self): | |
usuario = users.get_current_user() #Obtenemos el usuario actual si esta autenticado | |
if usuario: | |
self.response.write('<html><body>' + usuario.nickname() + ' usted registró:') | |
self.response.write(cgi.escape(self.request.get('content'))) #inserta el contenido registrado en la pagina Home | |
self.response.write('</body></html>') | |
else: | |
self.redirect(users.create_login_url(self.request.uri)) #Si no tenemos usuario autenticado podemos enviarlo con un redirect a la pantalla de autenticacion | |
application = webapp2.WSGIApplication([ | |
('/', Home), | |
('/registro', Registro), | |
], debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment