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