Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django 2: project root url namespace not working

Tags:

url

django

I have the following url patters in the project root's urls.py:

from django.contrib import admin
from django.urls import path, include


urlpatterns = [
    path('admin/', admin.site.urls),
    path('main/', include('main.urls', namespace='main')),
]

But django complains with the following message:

django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead.

According Django's documentation, the pattern of 'main' should be correct. What's the problem?

like image 235
Randy Tang Avatar asked Jan 04 '18 09:01

Randy Tang


1 Answers

You need to add app_name = 'main' to the main.urls file. See example and description here.

like image 59
neverwalkaloner Avatar answered Sep 28 '22 07:09

neverwalkaloner