【问题标题】:Mapping URLs in my handler script in App Engine在 App Engine 的处理程序脚本中映射 URL
【发布时间】:2011-08-12 00:39:24
【问题描述】:

我有

class Auth(webapp.RequestHandler):
    def get(self,username,password):
        self.response.out.write("auth" + self.request.get("username"))

我的网址的结构是:

/api/auth/?username=xxxx&password=xxxx

如何在我的处理程序脚本中映射此 URL?

【问题讨论】:

  • 您有机会使用 POST 代替吗? GET 中的密码不是最佳实践。 (额外的功劳:在网络上使用比普通密码更好的东西)

标签: python google-app-engine url mapping


【解决方案1】:

处理程序:

class Auth(webapp.RequestHandler):
    def get(self):
        self.response.out.write("username" + self.request.get("username"))
        self.response.out.write("password" + self.request.get("password"))

网址:

/api/auth?username=xxxx&password=xxxx

应用:

application = webapp.WSGIApplication([
    ('/api/auth', Auth),
    ], debug=True)

【讨论】:

  • 不知道为什么你的不工作,但我得到了这个工作 (/api/auth/(.*)(.*)',Auth)
  • @jwesonga 之所以有效,是因为(.*) 匹配空字符串,并且您有两个附加参数“用户名”和“密码”。从您的处理程序中删除这些参数 - 您必须使用 self.request.get 来获取查询字符串参数。
猜你喜欢
  • 2014-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-12
相关资源
最近更新 更多