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 have if i) , last item list [-1] , convert integer builtin int() function

code:

object_id = int([i in str(request.path).split('/') if i][-1]) print(object_id) 

output:

15 

Comments

Popular posts from this blog

java - How to Configure JAXRS and Spring With Annotations -

visual studio - TFS will not accept changes I've made to a Java project -

php - Create image in codeigniter on the fly -