1

I have designed the following url pattern

re_path(r'^api/refresh-token/(?P<token>[1-9]+\_[0-9a-f]{32}\Z)/$',refresh_token)

1_6506823466dc409a93b83b2c5f3b7cf2 matches the pattern [1-9]+\_[0-9a-f]{32}\Z.

enter image description here

But when i hit the url it is not found.

System check identified no issues (0 silenced).
March 15, 2021 - 02:10:29
Django version 3.1.7, using settings 'tokenproject.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Not Found: /api/refresh-token/1_6506823466dc409a93b83b2c5f3b7cf2/
[15/Mar/2021 02:10:32] "PUT /api/refresh-token/1_6506823466dc409a93b83b2c5f3b7cf2/ HTTP/1.1" 404 3279
3
  • It does not match if you add a slash at the end. \Z assumes end of the string before the line terminator, but then there is still a slash to match. Commented Mar 14, 2021 at 21:04
  • 1
    Just work with r'^api/refresh-token/(?P<token>[1-9]+\_[0-9a-f]{32})/$' Commented Mar 14, 2021 at 21:07
  • @WillemVanOnsem Thanks it worked ! Commented Mar 14, 2021 at 21:11

1 Answer 1

2

The \Z asserts the end of the string, or before the line terminator, but there is still content to match: the slash at the end, so the \Z makes it impossible to satisfy any string at all.

You do not need to use \Z at all here, since there is no multi-line, and $ already matches the end of the line.

You this can implement this with:

re_path(r'^api/refresh-token/(?P<token>[1-9]+\_[0-9a-f]{32})/$', refresh_token)
Sign up to request clarification or add additional context in comments.

Comments

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.