How to check name of Django url in view

Viewed 2137

say this is my url:

url(r'^$', mainApp_views.homepage),

Is it possible to check this text = "mainApp_views.homepage" in view and middleware ?

Thanks in advance,

2 Answers

As of Django 2.0, you need to import resolve from django.urls:

from django.urls import resolve

def your_view(request):
    url_name = resolve(request.path).url_name
    print(url_name) #prints the "name" attribute in your urlpatterns
Related