Flask Learning – Multi level URL
Flask is a lightweight WSGI web application framework.
Today we’ll talk about some useful feature of Flask.
For example, such a URL is used to query movies by name:
The router corresponding to flask is /movie/name/<moviename >
Here comes the question:
If the user queries the name with / such as
Then the router above can’t match. It can be written as:
In this way, you can get moviename = Avenger Alliance / 2019, and then deal with it
2.Multi level URL
In fact, the above application is just to solve the problem of seemingly multi-level URLs. There is a real multi-level URL scenario, such as the photo address of cloudflare. You can see the following /w/1240, which is actually equivalent to ?w=1240, but this parameter is not necessary. If you do not use the path method, you need to define multiple routes, and only one route needs to be defined in the path method like /images/<path:subpath>
Flask parameters support these types of values, you can use them process you params.