在以下代码中,在localhost上运行时,用户总是无。我假设有一种预加载数据的方法,但我无法弄清楚如何。
from google.appengine.api import users
user = users.get_current_user()
在localhost上运行时处理用户的“正确”方法是什么?
答案 0 :(得分:1)
您不需要做任何特别的事情,get_current_user
不应该总是无。
您确定要实际登录用户吗?您可能需要将app.yaml中的处理程序设置为login: required
,以将用户重定向到登录表单。
答案 1 :(得分:1)
您始终可以通过此地址http://localhost:8080/_ah/login
在localhost上使用虚拟用户登录(如果您在默认的8080端口上运行)。
但通常您会使用users.create_login_url()
将用户重定向到登录页面,它会在localhost和生产中正确处理。