SoFunction
Updated on 2025-03-01

Detailed explanation of url mapping of python script framework webpy

URL exactly match (specific url)

/index

URL fuzzy matching (you don't know what is behind index at all, it won't return parameters at all)

/index/\d

URL with group matching (the main function is '()', which mainly returns parameters. You must have a parameter in the class you process)

/baidu/(.*)

Example

import web
urls=('/index','AbsoluteUrl',
    '/index/\d','AmbiguousUrl',
    '/index/(.*)','GroupUrl')
#Specific url processing classclass AbsoluteUrl:
    def GET(self):
        ('Content-type','text/html;charset=utf-8')
        return u'URLExact match'
#fuzzy url processing classclass AmbiguousUrl:
    def GET(self):
        ('Content-type','text/html;charset=utf-8')
        return u'URLFuzzy Match'
#Group url processing classclass GroupUrl:
    def GET(self,name):  #If you are matching with group here, be sure to add parameters to receive the parameters you return        ('Content-type','text/html;charset=utf-8')
        return u'URLWith group matching--'+name
app=(urls,globals())
if __name__ == '__main__':
    ()

question

1. Why can't urls use dict? Is it related to its principle?
2. What are the functions of globals()
3. Why http://0.0.0.0:8080/, why do we have to localhost:8080 when running? What are the benefits of this design?

The above is the detailed explanation of the url mapping of webpy in the python script framework. For more information about webpy's url mapping, please pay attention to my other related articles!