Reputation: 514
models.py
from django.conf.urls import include, url
app_name = "Review"
urlpatterns = [
url(r'^books/', include("Review.urls", namespace='reviews')),
]
Review\urls.py
from django.conf.urls import include, url
from django.contrib import admin
from .views import (
ReviewUpdate,
ReviewDelete,
)
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'),
]
I am providing app_name before my urlpatterns. But it's giving me error while running my code. The errors are given below:
File "E:\workspace\python\web\Book_Review_App\Book\urls.py", line 13, in <module>
url(r'^books/', include("Review.urls", namespace='reviews')),
File "E:\workspace\python\web\Book_Review_App\venv\lib\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.
Please help.
Upvotes: 3
Views: 7901
Reputation: 129
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')),
]
Upvotes: 0
Reputation: 1204
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),
]
Upvotes: 9