Access URI Parameters via webapp2

醉酒当歌 提交于 2021-02-08 12:52:38

问题


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)

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).


回答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)


来源:https://stackoverflow.com/questions/12934427/access-uri-parameters-via-webapp2

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