[Django]-Specifying a namespace in include() without providing an app_name

9👍

The app_name needs to be set in your app’s urls.py not the main urls.py.

In review.urls.py add the following,

from django.conf.urls import include, url 
from django.contrib import admin 
from .views import ( ReviewUpdate, ReviewDelete, )

app_name = 'Review'

urlpatterns = [ 
    url(r'^reviews/(?P<pk>\d+)/edit/$', ReviewUpdate.as_view(), name='review_update'),
    url(r'^reviews/(?P<pk>\d+)/delete/$', ReviewDelete.as_view(), name='review_delete'),
]

and remove the app_name from the main urls

EDIT: for the admin issue that the op mentioned in the comments,
in the main urls.py

from django.urls import path

urlpatterns = [
    path('admin/', admin.site.urls),
]
👤at14

0👍

You need to define app_name in urls.py and pass urlconf_module in tuple . Here is example

app_name = "example"
from typing import NamedTuple
class NamedURL(NamedTuple):
    urlconf_module: None
    app_name: None

daily_urls = NamedURL(<your custom urls in list>, "example")

urlpatterns = [
    ...
    re_path(r'^daily/', include(daily_urls, namespace='daily')),
]
👤AndyC

Leave a comment