App Engine if elif else working on dev but not production

血红的双手。 提交于 2020-01-07 04:03:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!