Remove leading and trailing slash / in python

sumit picture sumit · May 2, 2012 · Viewed 71.2k times · Source

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

I need it as get/category (without leading and trailing slash).

How can I do this?

Answer

Amber picture Amber · May 2, 2012
>>> "/get/category".strip("/")
'get/category'

strip() is the proper way to do this.