Question

Supposing that I have something like that in my urls.py:

url(r'^task/(?P<pk>[0-9]+)/', taskview, name='taskview')

How can django help me extract '10' (or {"pk": 10}) from reading any matching URL string like:

  • /task/10/
  • /task/10///
  • /task/10/dddd/dddd/dddwwwww/wwwwq/qqqqqqw/qwead/?adawd=awodawdoij

?

(FYI when I say "reading any URL string" I mean that I am not receiving a request on those urls, but rather that I have such a string in my code on which I have to perform the aforementioned keyword extraction)

Was it helpful?

Solution

Just figured it out:

from django.urls import resolve
resolve(url).kwargs
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top