python - How to extract a number from a request.path in Django -
i'm looking way extract number request.path in django. number id of object. when print request.path gives me following:
>>>print request.path /post/v2/delete-document/15/
i extract number 15 since id of object being deleted. make equal variable called object_id:
object_id = 15
how can go doing this?
how this?
explanation:
first, split string
/
character, , make sure, result doesn't contain empty strings (that's why haveif i
) , last item list[-1]
, convert integer builtinint()
function
code:
object_id = int([i in str(request.path).split('/') if i][-1]) print(object_id)
output:
15
Comments
Post a Comment