I have a simple AppEngine application that has one file named WebInterface.py
responsible or routing the user to the correct pages with the following code:
import webapp2
from handlers import MainHandler
from handlers import PageOneHandler
from handlers import PageTwoHandler
app = webapp2.WSGIApplication([
('/', MainHandler),
('/pageOne', PageOneHandler),
('/pageTwo', PageTwoHandler)
], debug=True)
And another handlers.py
that contains all the RequestHandlers responsible of displaying pages to the user. It has the following code:
import webapp2
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.write('Hello, You are in the Main Page!')
class PageOneHandler(webapp2.RequestHandler):
def get(self):
self.response.write('Hello, You are in the First Page!')
self.response.write('<br><html><head><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script></head> <body>')
self.response.write('<button id="btn" onClick="doAction()">Click Me')
self.response.write('</button><p id="demo"></p>')
self.response.write('<script>')
self.response.write('function doAction()')
self.response.write('{document.getElementById("demo").innerHTML="Hello World";')
self.response.write('var data = {')
self.response.write('user : "UserName", pwd : "Password"')
self.response.write('};')
self.response.write('jQuery.post("/pageOne", data);')
self.response.write('}')
self.response.write('</script>')
self.response.write('</body></html>')
def post(self):
self.redirect('/pageTwo')
class PageTwoHandler(webapp2.RequestHandler):
def get(self):
self.response.write('Hello, You are in the Second Page! Get method')
def post(self):
self.response.write('Hello, You are in the Second Page! Post method')
Well, when I try to access one of the three pages I get the expected results, for example if I type in my browser this address: http://localhost:13080/
I get the Main page as a result, If I enter this address: http://localhost:13080/pageOne
I get the first page and if I enter this address: http://localhost:13080/pageTwo
I get the second page as expected.
Now, my problem is that when clicking on the Click Me
button in the first page, The HTTP POST
request is sent and PageOneHandler
's post method is executed, which is supposed to redirect me to the pageTwo
and it does! We can see the proof in the Console:
INFO 2014-03-13 10:36:47,831 module.py:612] default: "GET /pageOne HTTP/1.1" 200 405
INFO 2014-03-13 10:37:08,606 module.py:612] default: "GET /pageOne HTTP/1.1" 200 409
INFO 2014-03-13 10:37:32,065 module.py:612] default: "POST /pageOne HTTP/1.1" 302 -
INFO 2014-03-13 10:37:32,090 module.py:612] default: "GET /pageTwo HTTP/1.1" 200 45
But I am still in the same page (/pageOne
). So why I didn't get the text contained in pageTwo
's get method ?
Thank you.