删除前/后斜杠/在Python中 [英] Remove leading and trailing slash / in python

查看:71
本文介绍了删除前/后斜杠/在Python中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用request.path返回Django中的当前URL,并且它正在返回/get/category.

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

我需要它作为get/category(没有前导和尾部斜杠).

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

我该怎么做?

推荐答案

>>> "/get/category".strip("/")
'get/category'

strip()是执行此操作的正确方法.

strip() is the proper way to do this.

这篇关于删除前/后斜杠/在Python中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆