LA_
LA_

Reputation: 20409

Default value with WSGIApplication Handler?

I have the following code:

class MyHandler(webapp.RequestHandler):
    def get(self, page_text, page=1): # page default value is 1, but it doesn't work

application = webapp.WSGIApplication([('/something/(page(\d+))?/?', MyHandler)], debug=True)

It should capture URLs like:

/something/
/something/page1
/something/page1/
/something/page2
/something/page2/
/something/pageN
/something/pageN/

When first URL is used (/something/), I still expect to have page equal to 1, but really page is equal to None. Why does it happen so?

Upvotes: 2

Views: 123

Answers (2)

Niklas Rosencrantz
Niklas Rosencrantz

Reputation: 26655

Here's a nearly identical structure I use and I recommend it:

class PageHandler(BaseHandler):
  def get(self, page_id):

('/page/([0-9]+)', PageHandler),

I doesn't exactly answer the question but since I'm very pleased with that and it can do what you want (pages with ID numbers) you may find it useful.

Upvotes: 0

systempuntoout
systempuntoout

Reputation: 74104

Just a workaround waiting for some regex guru answer:

class MyHandler(webapp.RequestHandler):
    def get(self, page_text = None, page = 1)

application = webapp.WSGIApplication([('/something/', MyHandler)
                                     ('/something/(page(\d+))?/?',MyHandler)], 
                                     debug=True)

Upvotes: 1

Related Questions