How to Solve Error Message ‘url’ is not a registered namespace in Django Application

Posted on

Introduction

Apparently, this article is pointing out about how to face an error appear upon modifying an URL address definition. Actually, if there are too many applications or modules available in the Django-based application or Django-based module, it will end up really difficult especially for maintaining the URL address definition. At certain point, there will be a confusion and probably an error appear because of the same URL address pattern. So, in order to avoid confusion, there is an attempt to include the application or module name as part of the URL address. For an example, as part of the URL name definition, the organization module will have ‘org-list’, ‘org-edit’ , etc. Moreover, there is also an attempt to modify it into a certain pattern as ‘org:list’, ‘org:edit’, etc.

But unfortunately, defining the URL address name by the pattern format of ‘org:list’, ‘org:edit’ will eventually triggering an error message. The following is the error message appear after accessing the page :

NoReverseMatch at /org/help/
'org' is not a registered namespace
Request Method:
GET
Request URL:http://localhost:8001/org/help/
Django Version:3.2.6
Exception Type:NoReverseMatch
Exception Value:'org' is not a registered namespace
Exception Location:C:\app\python39\lib\site-packages\django\urls\base.py, line 82, in reverse
Python Executable:C:\app\python39\python.exe
Python Version:3.9.7
Python Path:['C:\\programming\\python\\django\\myproject',
 'C:\\app\\python39\\python39.zip',
 'C:\\app\\python39\\DLLs',
 'C:\\app\\python39\\lib',
 'C:\\app\\python39',
 'C:\\app\\python39\\lib\\site-packages']
Server time:Wed, 20 Oct 2021 18:20:34 +0000

The following is the definition of the URL address in the ‘urls.py’ file where it is exist in the ‘org’ folder or the application folder.

    
path("help/", views.multi_search, name="org:help"),

Furthermore, the following is the actual execution of the command for defining on including URL address of the application in the file with the name of ‘urls.py’ :

from django.contrib import admin
from django.urls import path, include  # add this

urlpatterns = [
    path('admin/', admin.site.urls),          # Django admin route
    path('org/', include('org.urls')),
]

Solution

The solution is very simple. The pattern name of the URL address which is triggering the error message. The error is reacting to the URL name definition of ‘org:help’ in the urls.py exist in the folder of the application. The name ‘org’ before the colon character It is considered as a name of a namespace. So, instead of using the colon (:), pick another safe character either underscore (_) or even dash (-). The example above is using dash (-) for creating some sort of identifier in the URL address’ name. So, change it as follows :

    
path("help/", views.multi_search, name="org-help"),

Try to execute and access the page once more. If there are no other error appear, the page will render normally.

Leave a Reply