Question: How can I design a set of URL handling and scheduling scenarios for the entire site?
Solution: Webpy's URL handling scheme is simple but powerful and flexible. At the top of each app, you'll often see a complete URL scheduling scheme defined in the tuple. For example:
URLs = ( "/tasks/?","signin", "/tasks/list","Listing", "/tasks/post","Post", "/tasks/chgpass","Chgpass", "/tasks/act","Actions", "/tasks/logout","Logout", "/tasks/signup","Signup")
The format for this tuple is: Url-pattern-path,handler-class This pattern repeats more URL patterns. If you don't understand the relationship between URL patterns and processing classes, check out Hello World example or quick Start tutorial in your
Read the other parts of cookbook before.
path-matching path matching
You can use powerful regular expressions to design a more flexible URL pattern. For example,/(TEST1|TEST2) matches either of the/test1 or/test2. The key is to understand that the match occurs on the path of your URL.
For example, the following URL:
http://Localhost/myapp/greetings/hello?name=joe
The path to the URL is/myapp/greetings/hello. Webpy will add a ^ and $ to the URL pattern internally, so that/tasks/will not be able to match the/tasks/addnew pattern. When matching a path, you cannot use the pattern:/tasks/delete?name= (. +) as the following section is called Query (string), so it cannot be correctly matched. For a more detailed description of the URL, refer to Web.ctx.
Capturing parameters Capture parameters
You can capture the parameters in the URL pattern for your processing class:
" /users/list/(. +) " " list_users "
A block of data captured after list/can be used as a parameter in a GET or post:
class list_users: def GET (self, name): return'Listing info about User: {0} ". Format (name)
You can define multiple parameters. Also note that the parameters in the URL string (that is, the part that appears later) can be obtained using web.input ().
In the case of the intended sub-application Note sub-application
To better handle larger Web applications, Webpy also supports sub-application when you design a URL scheme for a child app, keep in mind that the path (Web.ctx.path) will deprive the parent of the path. For example, if you are in the main app, you define a URL pattern/blog
Jump to the blog sub-app, in your blog sub-app all the URL patterns will be/start instead of/blog. See Web.ctx for more details on getting cookbook rules.
Webpy Learning notes-understanding URL Processing