I know django.conf.urls.defaults.url extracts regular expression to get object-id or others.
I wonder if I can do the same thing in my view.
Suppose I have a url rule such as url(r'^/path1/path2/(?P<my_object_id>\d+)/path3, my_view, name='my_view_name')
In a view, I have a string that matches the url such as /path1/path2/34/path3
, how can I get the 34
from the string?
ie, Is there a function which takes view_name(or the same url regex in urls.py), and a url string and returns positional/keyword arguments as the url()
does it?
foo(view_name, url_string):
...
return (args, kwargs)