问题
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?
回答1:
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.
回答2:
You first need to log in via users.create_login_url()
来源:https://stackoverflow.com/questions/10906696/app-engine-if-elif-else-working-on-dev-but-not-production