Detailed Explanation of url Mapping of python Script Framework webpy
- 2021-12-13 08:48:05
- OfStack
URL exact match (specific url)
/index
URL Fuzzy Matching (You have no idea what follows index, it will not return parameters at all)
/index/\d
URL with group matching (there is mainly a '()', which is mainly used to return parameters, and 1 in the class you are dealing with must have a parameter accepted)
/baidu/(.*)
Instances
import web
urls=('/index','AbsoluteUrl',
'/index/\d','AmbiguousUrl',
'/index/(.*)','GroupUrl')
# Specific url Handling class
class AbsoluteUrl:
def GET(self):
web.header('Content-type','text/html;charset=utf-8')
return u'URL Exact match '
# Fuzzy url Handling class
class AmbiguousUrl:
def GET(self):
web.header('Content-type','text/html;charset=utf-8')
return u'URL Fuzzy matching '
# Grouped url Handling class
class GroupUrl:
def GET(self,name): # If you have a band match here, 1 Be sure to add parameters , Used to receive the parameters you return
web.header('Content-type','text/html;charset=utf-8')
return u'URL Band group matching --'+name
app=web.application(urls,globals())
if __name__ == '__main__':
app.run()
Problem
1. Why urls can't use dict is it related to its principle
2. What else does globals () do
3. Why is http://0.0. 0.0: 8080/? Why do we have to use localhost: 8080 when we run? What are the benefits of this design?
The above is the python script framework webpy url mapping details, more about webpy url mapping information please pay attention to other related articles on this site!