Remove leading and trailing slash / in python

前端 未结 3 643
囚心锁ツ
囚心锁ツ 2021-02-01 11:47

I am using request.path to return the current URL in Django, and it is returning /get/category.

I need it as get/category (witho

3条回答
  •  名媛妹妹
    2021-02-01 12:16

    Another one with regular expressions:

    >>> import re
    >>> s = "/get/category"
    >>> re.sub("^/|/$", "", s)
    'get/category'
    

提交回复
热议问题