通过webapp2访问URI参数 [英] Access URI Parameters via webapp2

查看:61
本文介绍了通过webapp2访问URI参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to access the URI parameters of the given request:

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

我无法使以下代码正常工作,

I can't make the following code work though,

main.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个错误(内部服务器错误).

I think there's something wrong on my main.py, but I tried to mess with it by adding named routes and regex's, but I just kept getting 500 errors (Internal Server error).

推荐答案

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)

这篇关于通过webapp2访问URI参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆