This article describes the URL mapping, before we introduce the mapping, we first understand what is the URL? The URL (uniform/universal Resource locator abbreviation, Uniform Resource Locator) is a concise representation of the location and access to resources available on the Internet and is the address of standard resources on the Internet. Each file on the Internet has a unique URL that contains information about the location of the file and how the browser should handle it. Know what is a URL, then URL mapping is good to understand. White words on the basis of the matching rules of the URL to find the corresponding page.
1.URL three kinds of mappings
1 URL exact match, format:/index
Explain, in the browser input http://localhost:8080/index, then will exactly match "/index" such a page.
2 URL fuzzy matching, format:/index\d+
Explanation: This means starting with "/index," followed by a number or a number of URLs such as a URL to match, for example, browser input: http://localhost:8080/index123 or http://localhost:8080/ Index4, this kind of fuzzy matching, generally requires the use of regular expressions.
3 URL with group matching, format/index (\d+)
Explanation: This band match seems to match the above Blur, because adding a bracket outside the regular expression means matching a group.
2. Modify our previous hello.py content to practice URL mapping
Import Web
urls = (
'/index ', ' Index ',
'/blog/\d+ ', ' blog ',
'/(. *) ', ' Hello '
)
app = Web.application (URLs, Globals ())
class Hello:
def get (self, name): Return
' hello ' + name
class index:< C10/>def Get (self): return
"Index method"
class Blog:
def get (self): return
' blog Get method '
def POST (self): return
' blog POST method '
if __name__ = = "__main__":
App.run ()
Through the code above, we can see that we write URL mapping to the structure of URLs, the top match is a complete match, the matching result range is very small, the middle is fuzzy match, the matching range is larger, and the third is any match (. *) to represent any character, the result range is larger. This need to maintain such norms, from small to large range.
3. Test run a different URL to verify that the set match is successful
3.1 Full match
3.2 Fuzzy Matching
3.3 Any match