I don’t understand what could be wrong with this code for rendering pages.
def post(self):
acct = self.request.get('account')
pw = self.request.get('password')
que = db.Query(User)
que = que.filter('account =', acct)
que = que.filter('password =', pw)
results = que.fetch(limit = 1)
values = { }
newval = dict(values)
newval['path'] = self.request.path
if len(results) > 0:
path = os.path.join(os.path.dirname(__file__), 'templates/sites.htm')
self.response.out.write(template.render(path, {}))
I call it from a login form located on a page named “loginscreen.htm”.
When the application reaches this part of the code:
if len(results) > 0:
path = os.path.join(os.path.dirname(__file__), 'templates/sites.htm')
self.response.out.write(template.render(path, {}))
and attempts to redirect to ‘sites.htm’, the page ‘sites.htm’ is correctly displayed but in the address bar it’s still showing:
‘http://localhost:8080/login’ (“/login” routes incoming request from “loginscreen.htm”) when ‘http://localhost:8080/sites.htm’ should
be shown instead.
The main problem with this is that if I reload the page, the “Confirm Form Resubmission” dialog appears allowing users to submit the form again.
But if I replace
path = os.path.join(os.path.dirname(__file__), 'templates/sites.htm')
self.response.out.write(template.render(path, {}))
by
self.redirect('sites.htm')
the address bar displays ‘http://localhost:8080/sites.htm’ correctly.
So what is wrong with the code?
Sorry if I made this question sound more complicated than it should be.
Thanks in advance!
Your problem is a misunderstanding here:
That code doesn’t do anything like a redirect — all it does is tell AppEngine to respond to that login attempt by rendering out the template at
sites.htmin response to the POST request. If you want to redirect, you need to do that explicitly (as you appear to have already tried).