2

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)

1 Answer 1

4

Just figured it out:

from django.urls import resolve
resolve(url).kwargs
Sign up to request clarification or add additional context in comments.

1 Comment

Now in new versions of Django it looks like: from django.urls import resolve

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.