答案 0 :(得分:5)
Yes there is - the urlparse
module。你得到的ParseResult
将以一种很好的方式剥离主机/协议,然后你就可以使用str的split()
来分割路径分隔符。
答案 1 :(得分:4)
如果您正在使用webapp,则可以“捕获”与您的处理程序匹配的正则表达式的部分,并将它们作为参数传递给您的处理程序。例如:
class FooHandler(webapp.RequestHandler):
def get(self, fruit, number):
# Do something with your fruit and number (which are both strings, remember!)
application = webapp.WSGIApplication([
('/([^/]+)/(\d+)', FooHandler),
])