9

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

GaiusSensei
  • 1,860
  • 4
  • 25
  • 44
  • 1
    I suspect the regexp using '/account/user// only works with the URL parts, not the query part (which you wouldn't expect to be part of routing) – tesdal Oct 18 '12 at 12:09

1 Answers1

19
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)
alex
  • 2,450
  • 16
  • 22