Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to list all Django registered URL namespaces?

Tags:

django

I'm getting an %s is not a registered namespace error in Django 1.11. Is there a way to list what all the registered namespaces are?

like image 473
Al Sweigart Avatar asked Apr 07 '17 21:04

Al Sweigart


People also ask

What is Django URL namespace?

URL namespaces allow you to uniquely reverse named URL patterns even if different applications use the same URL names. It's a good practice for third-party apps to always use namespaced URLs (as we did in the tutorial). Similarly, it also allows you to reverse URLs if multiple instances of an application are deployed.

What is Urlpatterns Django?

Every URLConf module must contain a variable urlpatterns which is a set of URL patterns to be matched against the requested URL.

What is reverse URL in Django?

the reverse function allows to retrieve url details from url's.py file through the name value provided there. This is the major use of reverse function in Django. Syntax: Web development, programming languages, Software testing & others. from django.urls import reverse.


1 Answers

You could do the same what reverse actually does: look them up in the namespace_dict:

from django import urls

url_resolver = urls.get_resolver(urls.get_urlconf())
url_resolver.namespace_dict.keys()
like image 63
ezdazuzena Avatar answered Oct 17 '22 17:10

ezdazuzena