0

In my django rest framework app I have Urls.py as follows:

from django.urls import include, path
from .shipper import*
from .views import *


urlpatterns = [path('shipper/',
                    include(path('shipperitems/', MasterItemsList.as_view()),
                            path('shippercreateapi/', shipperCreateAPIView.as_view()),)),

               ]

When I try to run the app it gives me the following error:

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 t he list of patterns and app_name instead.

what should I do to resolve this ?

Rahul Sharma
  • 2,187
  • 6
  • 31
  • 76
  • Encounter the same problem when learning `djangorestframework`. Seems the tutorial from rest_framework is outdated. https://www.django-rest-framework.org/tutorial/quickstart/#urls – Simba Apr 13 '21 at 08:33

2 Answers2

1

You are using the include(...) function in the wrong way. include(...) usually takes the module which contains url-patterns. So change your code as below,

#root urls.py
from django.urls import include, path

urlpatterns = [
    path('shipper/', include('shipper.urls')),
]

and

#/shipper/urls.py
urlpatterns = [
    path('shipperitems/', MasterItemsList.as_view()),
    path('shippercreateapi/', shipperCreateAPIView.as_view()),)),

]
Andre Miras
  • 3,580
  • 44
  • 47
JPG
  • 82,442
  • 19
  • 127
  • 206
0

Check the docs for include here. You should pass paramters to include like this

url(r'^reviews/', include('app_name.urls', 'app_name'), namespace='app_name')),

(credits)

Muhammad Hassan
  • 14,086
  • 7
  • 32
  • 54