App Engine if elif else working on dev but not pro

2019-09-14 18:18发布

When I run the following code

user = users.get_current_user()
if users.is_current_user_admin():
    loggedin = 'Admin'
elif user:
    loggedin = 'User'
else:
    loggedin = 'Anonymous'

on the development environment I get Admin when logged in as an Administrator, User as a User, and Anonymous when not logged in. When on production I always get Anonymous. Why is this not working?

2条回答
在下西门庆
2楼-- · 2019-09-14 18:42

You first need to log in via users.create_login_url()

查看更多
Fickle 薄情
3楼-- · 2019-09-14 18:53

The problem has nothing to do with if/elif/else or users.create_login_url(). The issue is with App Engine not recognizing a logged in user on a http request when the user logged in with HTTPS with users.create_login_url(). I've created a new question on this here. I believe it has something to do with how the cookie is being set.

The reason the code was working on Dev and not production is how the development environment handles HTTPS urls it remaps it to http and serves the request avoiding the problem.

查看更多
登录 后发表回答