本文介绍了NotAllowedError在前面的主页'/'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将用户的主页'/'设置为登录或不登录,但是我得到一个 NotAllowedError 。这在本地服务器中有效。然而,它在真正的公共服务器中似乎不起作用。

I tried to set the Main Page '/' for users to login or not login, but I get a NotAllowedError. This works in the local server. However, it does not seem to work in the real public server.

NotAllowedError 意味着遵守Google App Engine标准,不要在首页上登录,也可能是其内容其他?

Does NotAllowedError mean complying to Google App Engine standards of not putting a login on the front page or maybe its something else?

这是错误:

Traceback (most recent call last):
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__
    rv = self.handle_exception(request, response, e)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
    rv = self.router.dispatch(request, response)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
    return route.handler_adapter(request, response)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
    return handler.dispatch()
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch
    return method(*args, **kwargs)
  File "/base/data/home/apps/s~map-jobs/2.371277816538602179/main.py", line 294, in get
    user_url = users.create_login_url() # raise NotAllowedError
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/users.py", line 256, in create_login_url
    raise NotAllowedError
NotAllowedError

这是我的 MainHandler

Here is my MainHandler:

class MainHandler(BaseHandler):
  def get(self):
    user = users.get_current_user()
    logout_url = users.create_logout_url(self.request.uri)
    profile=''
    if user:
      profile = Profile.query(Profile.user_id==user.user_id())
      if profile.count() <= 0:
        profile = Profile()
        profile.user_id = user.user_id()
        profile.email = user.email()
        profile.firstname = user.nickname()
        profile_key = profile.put()
      else:
        profile_key = Profile.query(Profile.user_id==user.user_id())
      profile = profile_key.get()
      current_user = 'Hello, '+ user.nickname()
      user_url = logout_url
      title = "Click to logout from Google."
    else:
      current_user = 'Google Sign in'
      user_url = users.create_login_url(self.request.uri) # raise NotAllowedError
      title = "Click to sign in with your Google Account."
    values = {
      'current_user' : current_user,
      'user_url' : user_url,
      'profile' : profile,
    }
    self.render_html('index.html',values)

这是我的 webapp2的一部分。 WSGIApplication

app = webapp2.WSGIApplication([
  ('/', MainHandler),
], debug=True)

这是我的app.yaml: p>

Here is my app.yaml:

application: map-jobs
version: 2
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: /(.*\.(gif|png|jpg|js|css|woff|ttf|svg))
  static_files: static/\1
  upload: static/(.*\.(gif|png|jpg|js|css|woff|ttf|svg))

- url: /templates/.*
  script: templates.app

- url: .*
  script: main.app


libraries:
- name: webapp2
  version: "2.5.2"

- name: jinja2
  version: "2.6"


推荐答案

没关系,我只是犯了一个错误。我应该在应用程序设置中使用 Google帐户API 而不是 Google Apps域

Never mind, I just made a mistake. I should use Google Accounts API instead of Google Apps Domain in my Application settings.

这篇关于NotAllowedError在前面的主页'/'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-17 10:09