[Django]-Django – is not a registered namespace

99👍

You should just change you action url in your template:

<form action="{% url 'submit' %} "method='post'>

On the note of url namespaces…

In order to be able to call urls using home namespace you should have in your main urls.py file line something like:

for django 1.x:

url(r'^', include('home.urls', namespace='home')),

for django 2.x and 3.x

path('', include(('home.urls', 'home'), namespace='home'))

33👍

In your main project, open url.py first. Then check, there should be app_name declared at first. If it is not, declare it.

For example, my app name is user info which is declared in url.py

app_name = "userinfo"

urlpatterns = [
    url(r'home/', views.home, name='home'),
    url(r'register/', views.registration, name='register')
]

25👍

I also faced the same issue.
it is fixed now by adding

app_name = "<name of your app>" 

in app/urls.py

9👍

For Django 3.0, if you’re handling your urls within the app and using include with path, in your project/urls.py:

urlpatterns = [
    path(os.getenv('ADMIN_PATH'), admin.site.urls),
    path('', include('my_simple_blog.urls', namespace='my_simple_blog')),
    path('account/', include('account.urls', namespace='account')),
]

You need to specify namespace in include.

And then in your app/urls.py:

app_name = 'account'

urlpatterns = [
    path('register/', registration_view, name='register'),
    path('logout/', logout_view, name='logout'),
    path('login/', login_view, name='login'),
]

The app_name must match the namespace you’ve specified in project/urls.py.

Whenever you’re referring to these urls, you need to do it like this:

{% url 'namespace:name' %}

If you’re using it with redirect:

return redirect('namespace:name')

9👍

For the namespace error,
Make sure you have linked the app’s url in the main urls.py file

path('app_name/',include('app_name.urls'))

also in the urls.py of your app,make sure you mention the app’s name as

app_name='app_name'

Also make sure you have registered the app’s name on your installed apps in settings.py

3👍

As azmirfakkri has said if you’re using redirect, dont use this {% url 'namespace:name' %} syntax, use return redirect('namespace:name').

3👍

Probably 2 things could be a root cause,
in app/urls.py do include as below

app_name = 'required_name'

and in project urls.py also include the app_name

url(r'^required_name/$',views.home,name='required_name'),

Check: register app in settings.py INSTALLED_APPS

2👍

tag name must be unique in the urls.py file inside your application package inside the project! it is important for the template tagging to route whats what and where.

now [1] inside the urls.py file you need to declare the variable appName and give it the unique value. for example appName = "myApp"; in your case myHomeApp and [2] also define the urlpatterns list…

urlpatterns = [..., url(r'^submit/$', views.submit, name='submit'), ...];

in the html file just change the url tag to:

<form action="{% url 'myHomeApp:submit' %}" method='post'>

this should sifuce… else just write here and we’ll see how to continue on

2👍

A common mistake that I always find is when you have some name space in your template,
and in YourApp.url you don’t have any name space so if you should use name space add
in YourApp.url something like this
app_name = “blog”

then on your temples make sure you add your name space,
so you will have some thing like this “assumption errors are coming from edit.html
then on that particular template you will do this
"{% url 'blog:vote' pk=post.pk %}" "{% url 'blog:post_category' category.name %}"

2👍

if you happen to be nesting include(s, the namespace compounds, eg. topappname:appname:viewname

1👍

Maybe someone will find this suggestion helpful.

Go to your applications urls.py and type this before the urlpatterns:

app_name = 'Your app name'

1👍

For anyone who struggled on this error like me: After reading the solutions to this question, I was setting namespace in include function in a wrong urls file. Make sure you are modifying the right urls file. For me it was putting it in the main url.py besides settings.py. I hope this answer helps anyone who was confused as I was.

👤Salek

1👍

I got the same error below:

NoReverseMatch at /my_app1/
‘my_app1’ is not a registered namespace

So, I set account to my_app1 in my_app1/urls.py as shown below then the error was solved:

# "my_app1/urls.py"

from django.urls import path
from . import views

app_name = "my_app1" # Here

urlpatterns = [
    path("", views.index, name="index")
]

1👍

Check your urls.py

urlpatterns = [
    re_path(r'^submit/expense/$', views.submit_expense, name='submit_expense'),
    re_path(r'^submit/income/$', views.submit_income, name='submit_income'),
    re_path(r'^register/$', views.register, name='register'),

]

then open template.html
put for example register register in your HTML tag like this:

<a class="navbar-brand" href="{% url 'register' %}">

0👍

This worked for me:

In urls.py

urlpatterns = [
path("admin/", admin.site.urls),
path("", views.index),
path("test/", views.test, name = 'test')]

In views.py:

def test(request): 
return render(request, "base/test.html")

In the template:

 href="{% url 'test' %}"

0👍

I fixed it by using this on my main app’s urls so when I use this way This error disappear

In the main folder, where the setting is there, go to urls and
path("" , include("YourAppName.urls")),

Leave a comment