I am using request.path to return the current URL in Django, and it is returning /get/category.
request.path
/get/category
I need it as get/category (witho
get/category
def remove_lead_and_trail_slash(s): if s.startswith('/'): s = s[1:] if s.endswith('/'): s = s[:-1] return s
Unlike str.strip(), this is guaranteed to remove at most one of the slashes on each side.
str.strip()