deux
deux copied to clipboard
Django 2 error: Specifying a namespace in include() without providing an app_name
When using this library with Django 2 like:
from django.urls import include, path
urlpatterns = [
# ...
path('mfa/', include("deux.urls", namespace="mfa")),
]
Fails with:
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.
To make this work we need to add the variable app_name
to
deux/urls.py deux/oauth2/urls.py deux/authtoken/urls.py
with which value?
Use app_name='nameapp' in urls for applications, after urlpatterns
Can you provide a code example? Because as I'm typing app_name="sth" in urls.py it doesn't work.
Can you provide a code example? Because as I'm typing app_name="sth" in urls.py it doesn't work.
Let's say in your main urls.py
you want to include the urls of an app, called shop_app
, like this:
path("shop/", include("shop_app.urls", namespace='shop')),
Then, in your urls.py
file of your shop_app
located in shop_app/urls.py
, after the urlpatters add the app_name
like this:
urlpatterns = [
... some patterns
]
app_name = 'shop'
If you don't have access to the shop_app
urls, as in case you are using an included package, then you'll have to drop the namespace
from your main include and remove the namespace references from your url
tags, or from your reverse
functions.
Or you can also use it this way:
path('mfa/', include(("deux.urls", 'app_name'), namespace="mfa")),
Excelent ¡¡¡
as indicated by @DonExo
path('', include(('blog.urls', 'blog'), namespace='blog'))