Domanda

I'm building my new website using app-engine with python and webapp2 I'm having hard times to define the URIs in my web application

the result I need is:

http://www.example.com/
http://www.example.com/products/
http://www.example.com/products/table

I thought it's an easy task, but apparently it is not (for me, anyway)

I'm getting 404 error when I'm trying to load something like that: http://www.example.com/products/chair/

where is my mistake?

app = webapp2.WSGIApplication([
webapp2.Route('/', MainPage),
webapp2.Route('/products/', handler=MainProductsHandler),
webapp2.Route('/products/(\w+)/', handler=ProductHandler)
],debug=True)
È stato utile?

Soluzione

OK, I solved it. just like that:

app = webapp2.WSGIApplication([('/', MainPage), ('/product/.*', MainPage)], debug=True)

I think that I had a problem when I used the webapp2.Route method

thanks anyway

Altri suggerimenti

Your first approach would work using angle brackets wrapping the regular expresion like this:

app = webapp2.WSGIApplication([
webapp2.Route('/', MainPage),
webapp2.Route('/products/', handler=MainProductsHandler),
webapp2.Route('/products/<id:(\w+)>/', handler=ProductHandler)
],debug=True)

Don't forget to add the param id (or whatever name your choose for the regex match) to the handler's get method else it will complain about an unexpected param.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top