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 - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -