Search code examples
djangorequestdjango-urlsurl-pattern

Is there any way to get name of request path in Django


I wanted to get django re_path's name parameter value from request or in any way.

I have a url pattern like that,

re_path(r'^user/query/page/list$', views.UserListView.as_view(), name="user_list")

When request comes with user/query/page/list, I want to match it with name or directly get name of the path that described in re_path.

I checked all request data and didn't reach it.


Solution

  • It can be accessed from the request object

    current_url = request.resolver_match.url_name