The problem has nothing to do with if / elif / else or users.create_login_url (). The problem is that App Engine does not recognize the registered user in the HTTP request when the user is logged in with HTTPS with users.create_login_url (). I created a new question on this here . I believe this has something to do with how the cookie is set.
The reason code worked on Dev rather than production is because the development environment handles HTTPS URLs, redirects it to http and serves the request, avoiding the problem.
source share