Looked into how URLs should be handled, and wildcard URLs. Try this:
class ProductsHandler(webapp.RequestHandler):
def get(self, resource):
self.response.headers['Content-Type'] = 'text/plain'
table = self.request.url
self.response.out.write(table)
self.response.out.write("\n")
self.response.out.write(resource)
def main():
application = webapp.WSGIApplication([
('/products/(.*)', ProductsHandler)
],
debug=True)
util.run_wsgi_app(application)
When I go to the URL http://localhost:8080/products/table, I get this result:
http://localhost:8080/products/table
table
The resource parameter of the get function is passed in automatically by the WSGIApplication url_mapping, because it is mapped to:
('/products/(.*)', ProductsHandler)
The (.*) is a wildcard, and gets passed in as a method parameter.
You could name the parameter in the get method anything you want instead of resource, such as table. It wouldn't make a lot of sense though, because if you pass in a url like http://localhost:8080/products/fish, it would no longer contain the word "table".
Earlier attempt (before edits):
Try something like this:
class MainHandler(webapp.RequestHandler):
def get(self):
table = self.request.url
self.response.out.write(table)
For my test, I went to http://localhost:8080/, and it printed out:
http://localhost:8080/
See the docs for the Request class here.