【问题标题】:Access URI Parameters via webapp2通过 webapp2 访问 URI 参数
【发布时间】:2012-10-07 17:13:06
【问题描述】:

我想访问给定请求的 URI 参数:

http://localhost:8080/account/user?un=erik&pw=gaius

我不能让下面的代码工作,

ma​​in.py

app = webapp2.WSGIApplication([('/', MainPage),
                               ('/account/user', account.User)],
                              debug=True)

account.py

class User(webapp2.RequestHandler):
  def get(self, un, pw):
    self.response.headers['Content-Type'] = 'text/plain'
    self.response.write('Yey!' + un + ' ' + pw)

我认为我的 main.py 有问题,但我试图通过添加命名路由和正则表达式来解决它,但我一直收到 500 个错误(内部服务器错误)。

【问题讨论】:

  • 我怀疑使用 '/account/user// 的正则表达式仅适用于 URL 部分,而不适用于查询部分(您不希望它成为路由的一部分)

标签: python google-app-engine webapp2


【解决方案1】:
class User(webapp2.RequestHandler):
  def get(self):
    un = self.request.get('un')
    pw = self.request.get('pw')
    self.response.headers['Content-Type'] = 'text/plain'
    self.response.write('Yey!' + un + ' ' + pw)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-30
    • 1970-01-01
    • 2016-12-06
    • 1970-01-01
    • 1970-01-01
    • 2016-02-20
    相关资源
    最近更新 更多