deux icon indicating copy to clipboard operation
deux copied to clipboard

Django 2 error: Specifying a namespace in include() without providing an app_name

Open lopezjurip opened this issue 6 years ago • 7 comments

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

lopezjurip avatar Mar 14 '18 14:03 lopezjurip

with which value?

gonzaloamadio avatar Dec 24 '18 00:12 gonzaloamadio

Use app_name='nameapp' in urls for applications, after urlpatterns

VirtualKley avatar Jul 07 '19 00:07 VirtualKley

Can you provide a code example? Because as I'm typing app_name="sth" in urls.py it doesn't work.

rozacek avatar Feb 18 '20 09:02 rozacek

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.

GabrielDumbrava avatar Feb 21 '20 09:02 GabrielDumbrava

Or you can also use it this way:

path('mfa/', include(("deux.urls", 'app_name'), namespace="mfa")),

DonExo avatar Mar 21 '20 19:03 DonExo

Excelent ¡¡¡

amontecino avatar Apr 04 '20 19:04 amontecino

as indicated by @DonExo

path('', include(('blog.urls', 'blog'), namespace='blog'))

Gathiira avatar Aug 21 '21 06:08 Gathiira