from django.urls import resolve,reverse # reverse 通过别名获取url # resolve 通过url获取别名 # 使用resolve方法,该方法返回一个ResolverMatch对象,该对象有以下方法: func args kwargs url_name route app_name app_names namespace namespaces view_name def index(request): rm = resolve(request.path) app_name = rm.app_name url_name = rm.url_name