Skip to main content
 首页 » 编程设计

python之如何在 View 中检查 Django url 的名称

2025年02月15日22exmyth

说这是我的网址:

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

是否可以在 View 和中间件中检查此 text = "mainApp_views.homepage"?

提前致谢

请您参考如下方法:

你想要类似的东西

from django.urls import resolve 
 
 
def your_view(request): 
    # resolve the url from the path 
    url_name = resolve(request.path).url_name 

您可能也想将名称添加到您的网址 name='home'