以下内容为原创,转载请注明出处!

Django 2.1获取项目所有url地址

def get_url_all(self, patterns, pre_fix = "", result = []):
        for url_object in patterns:
            if "v1" in url_object.pattern._route:
                self.get_url_all(url_object.url_patterns, url_object.pattern._route)
            else:
                result.append(pre_fix + url_object.pattern._route)
        return result
	
	from . import urls
    result = self.get_url_all(urls.urlpatterns)
	print(result)

输出结果:

[‘manage/’, ‘logout/’, ‘’, ‘organization/v1/user/’, ‘organization/v1/user_ajax/’, ‘organization/v1/department/’, ‘log/v1/tree/’, ‘email/v1/send/’, ‘email/v1/index/’, ‘web/v1/apply/order/’, ‘web/v1/apply/order/int:pk/’, ‘web/v1/apply/ordertype/’, ‘web/v1/apply/orderclassify/’, ‘web/v1/apply/ordertype_add/’, ‘web/v1/apply/orderfield_add/’, ‘web/v1/apply/orderfield_delete/’, ‘web/v1/apply/fieldchoice_add/’, ‘web/v1/apply/fieldchoice_delete/’, ‘web/v1/apply/orderclassify_add/’, ‘web/v1/apply/orderclassify_edit/’, ‘web/v1/apply/orderclassify_delete/’, ‘web/v1/ods/account/’, ‘web/v1/ods/conf/’, ‘web/v1/ods/user/’, ‘web/v1/ods/user/int:pk/’, ‘web/v1/report/forms/’, ‘web/v1/report/permission/’, ‘web/v1/report/data/’, ‘web/v1/report/head/’]