regexdjangopython-3.xdjango-2.0

Decode url(r'^(?P<pk>[-\w]+)/$') to path() in Django


I need to convert the following regular expression using url() method to path() method.

url(r'^(?P<pk>[-\w]+)/$')

Thanks and regards.


Solution

  • try one of the patterns

    path('<int:pk>/')
    # or 
    path('<slug:pk>/')