Changing re_path to path is not working.

Hi!

I am migrating django from 2.2 to 4.1.3.

As part of it, I am replacing re_path with path.

path('', temporary_redirect(redirect_to='/accounts/login/'), name='root'),
re_path(r'^accounts/',
      MyTemplateView.as_view(
          template_name='auth/index.html',
          extra_context=settings.DEFAULT_CONTEXT
      ),
      name='authentication'
  ),

I changed the above to:

path('', temporary_redirect(redirect_to='/accounts/login/'), name='root'),
path('accounts/',
        MyTemplateView.as_view(
            template_name='auth/index.html',
            extra_context=settings.DEFAULT_CONTEXT
        ),
        name='authentication'
    ),

And it just does not work. When I try to visit /accounts/login/ page it says not found.
Changing back to re_path as it was just works.

I am not sure what the problem is.
Any thoughts on this?

There’s a huge difference between re_path and path.

The re_path of r'^accounts/' will match on any url starting with accounts/. This means that accounts/login/ will match.

However path is an exact match. 'accounts/' will not match 'accounts/login/'.

@KenWhitesell
Thank you for your answer.
That makes sense.
So I still need to use re_path in that case for that accounts/login/ endpoint, right?

Or change the path to accounts/login/, or any of a number of other possibilities. You are the one that needs to decide how your URLs are going to be dispatched.