lajarre
lajarre

Reputation: 5162

django find object from url

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:

?

(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)

Upvotes: 2

Views: 1590

Answers (1)

lajarre
lajarre

Reputation: 5162

Just figured it out:

from django.urls import resolve
resolve(url).kwargs

Upvotes: 4

Related Questions