How do I make a trailing slash optional with webapp2?

后端 未结 9 816
感情败类
感情败类 2021-02-12 15:30

I\'m using the new webapp2 (now the default webapp in 1.6), and I haven\'t been able to figure out how to make the trailing slash optional in code like this:

web         


        
9条回答
  •  粉色の甜心
    2021-02-12 16:26

    This works for me and is very simple. It uses the template format for URI routing in the webapp2 Route class. Trailing slash in this example is optional with no redirection:

    webapp2.Route('/your_url<:/?>', PageHandler)
    

    Everything after the colon between the chevrons is considered to be a regex: <:regex>

提交回复
热议问题