django url resolver problem

26 views
Skip to first unread message

Ali Osman Yüce

unread,
Mar 6, 2020, 6:07:29 AM3/6/20
to django...@googlegroups.com
Hi all,

I have encountered a problem when trying to create views that have to include the same string in name. I created two views below.

The problem is here, when I tried to make a post request to revoke_token endpoint, this request always is handled by  'token/' endpoint(TokenView). I debugged url Django resolver, as far as I understood, Django always check include a string in the path, not an exact match. When it sees "token/" words in "token/" URL, it says I found the URL path and return TokenView as a handler. When I swap these two URL paths, it works well.

Is there anyone faced with this problem? Thanks in advance.

url("token/", TokenView.as_view(), name="token"),
url("revoke_token/", RevokeTokenView.as_view(), name="revoke-token"),

MH

unread,
Mar 6, 2020, 1:17:48 PM3/6/20
to Django users
Dear Ali

I am just new to this myself, but I think it comes to down to the question what is the first pattern that matches for django. As far as I know we can use the ^ in order to tell django/python that a pattern should be at the start of a string that is searched. So I am not mistaken, you could add that at the start and then it could work.

But here are other people with much more experience and I could be mistaken.

MH

unread,
Mar 6, 2020, 1:18:43 PM3/6/20
to Django users
So, I would perhaps try something like
url("^token/", TokenView.as_view(), name="token"),
url("^revoke_token/", RevokeTokenView.as_view(), name="revoke-token"),


Alvaro Orozco

unread,
Mar 6, 2020, 2:31:07 PM3/6/20
to django...@googlegroups.com
Can we please have a look at the project and app urls.py and also the view.py module.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b0c74ae4-8098-4cb4-99cc-3237955b41b8%40googlegroups.com.

aliosm...@gmail.com

unread,
Mar 6, 2020, 5:07:29 PM3/6/20
to django...@googlegroups.com
Thanks, it works well. We have to add start(^) and finish($) regex symbols to url names. Otherwise django resolver checks whether any url has contain request path.



On 6 Mar 2020, at 21:19, 'MH' via Django users <django...@googlegroups.com> wrote:


So, I would perhaps try something like
url("^token/", TokenView.as_view(), name="token"),
url("^revoke_token/", RevokeTokenView.as_view(), name="revoke-token"),


Reply all
Reply to author
Forward
0 new messages