Problems with using include in Django

0

I'm having trouble with the include function, according to the django documentation, the syntax is include(module, namespace=None) include(pattern_list) , include((pattern_list, app_namespace), namespace=None) .

Source code

from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static
from django.conf import settings

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

if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

Error

path('clientes/', include("cliente.urls", namespace="cliente")),
File "/home/phomint/DjangoProjects/Manager/myvenv/lib/python3.5/site-packages/django/urls/conf.py", line 39, in include

'Specifying a namespace in include() without providing an app_name '
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.
    
asked by anonymous 18.08.2018 / 16:05

1 answer

0

In your cliente.urls file, create a app_name='cliente' variable.

Example :

"""Arquivos urls.py que está em cliente"""
from django.urls import path
from . import views

app_name='cliente'

urlpatterns = [
    path('', views.index, name='index'),
]
    
18.08.2018 / 17:58