I’m currently experimenting with some APIs, and I’ll like to know how to use URLs as a parameter for an app. For example:
http://www.myapp.com/myapp/jack
prints out “hello jack”
or
http://www.myapp.com/myapp/john
prints out “hello john”
or http://www.myapp.com/myapp/john%20jack prints out “hello john jack”
I’d like some pointers on where I can look for this functionality. I have a feeling this is easy but I just can’t grasp it. Is it dependent on the framework I’m using? I’m very new to Python so I’m still coming to terms with Django and the likes. I’m using Python on Google App Engine with GAE’s bundled webapp framework.
This is currently the code I’m working with right now:
import cgi
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
class MainPage(webapp.RequestHandler):
def get(self,url=None):
self.response.out.write("hello " + str(url))
application = webapp.WSGIApplication([
(r'/(\w+)', MainPage)
],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
Wei,
You have to create a url pattern like when you get the request at
myappyou will parse the remaining url and display the message.for example
File
helloworld/app.yamlFile
helloworld/helloworld.pySo this will handle all you request at
/myapp/year/so from this you have to get the value after/myapp/and display the year.Note: Do for long url your self so you will get the idea how will it works :).