In Django I have a function that provides a list of all URL Patterns for my system. I am attempting to create a search feature that shows users links to a list of urls that they have permissions to view, but I cannot seem to figure out how to grab the associated permission from the view function.
How can I do this?
Here is my code so far:
def get_url_patterns():
from django.apps import apps
list_of_all_urls = list()
for name, app in apps.app_configs.items():
mod_to_import = f'apps.{name}.urls'
try:
urls = getattr(importlib.import_module(mod_to_import), "urlpatterns")
list_of_all_urls.extend(urls)
except ImportError as ex:
# is an app without urls
pass
for thing in list_of_all_urls:
# print(type(thing))
# print(type(thing.callback.__name__))
print(thing.callback.__dict__)
return list_of_all_urls