-
-
Save feanil/57eed1a950fbaaad1815b06e62150900 to your computer and use it in GitHub Desktop.
GET ALL VIEWS IN DJANGO APP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf import settings | |
from django.urls import URLResolver, URLPattern | |
root_urlconf = __import__(settings.ROOT_URLCONF) # import root_urlconf module | |
all_urlpatterns = root_urlconf.urls.urlpatterns # project's urlpatterns | |
def get_all_view_names(urlpatterns): | |
views = [] | |
for pattern in urlpatterns: | |
if isinstance(pattern, URLResolver): | |
views.extend(get_all_view_names(pattern.url_patterns)) # call this function recursively | |
elif isinstance(pattern, URLPattern): | |
view = pattern.callback | |
views.append(view) | |
return views | |
all_views = get_all_view_names(all_urlpatterns) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment