More elegant one-liner way for urls.py to recognize path that include / as well as no / in Django [duplicate]

I am using Django v4. This is my urls.py

from django.urls import path
from .views import UserList, UserDetail

urlpatterns = [
    path("users", UserList.as_view()),
]

http://127.0.0.1:8000/users works fine. However, http://127.0.0.1:8000/users/ with the slash at the end fails to work.

To solve this problem, here's the new urls.py.

from django.urls import path
from .views import UserList, UserDetail

urlpatterns = [
    path("users", UserList.as_view()),
    path("users/", UserList.as_view()),
]

It looks kind of repetitive and goes against DRY principle behind Django. Is there a more elegant one-liner to fix this problem? Answer need not be a one-liner as long as it doesn't look repetitive.

EDIT: Best answer I found is here django urls without a trailing slash do not redirect

Back to Top