Get the current user from BlobstoreUploadHandler

故事扮演 提交于 2019-12-02 05:27:26

Each App requires its own login, and every class needs to have users imported and declared if you want to use User class in the code.

from google.appengine.api import users import webapp2

class MyHandler(webapp2.RequestHandler):
    def get(self):
        user = users.get_current_user()
        if user:
            greeting = ('Welcome, %s! (<a href="%s">sign out</a>)' %
                        (user.nickname(), users.create_logout_url('/')))
        else:
            greeting = ('<a href="%s">Sign in or register</a>.' %
                        users.create_login_url('/'))

        self.response.out.write('<html><body>%s</body></html>' % greeting)

For more details please see this article - https://cloud.google.com/appengine/docs/python/users/

Lepi

in your app.yaml you have to add login: required or login: admin.

Example:

handlers:
- url: /upload_handler.*
  script: my_app.media_handlers.application
  login: required

After this, users.get_current_user() should work.

https://cloud.google.com/appengine/docs/python/config/appconfig#Python_app_yaml_Requiring_login_or_administrator_status

Other thread about this:Google App Engine get_current_user always return None, even if i'm logged

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